sql server 2008 - Email SQL query results -
i send email status of tables have been modified within day. tried:
exec msdb.dbo.sp_send_dbmail @profile_name='emailprofile', @recipients='myemail@email.com', @subject='import status', @body= 'data import precess completed.', @query = 'select object_name(object_id) tables, last_user_update updated sys.dm_db_index_usage_stats database_id = db_id(''databasename'') , last_user_update >= dateadd(day, 0, datediff(day, 0, current_timestamp))', @attach_query_result_as_file = 1, @query_attachment_filename ='results.txt' email came through file result.txt attached under tables column there no tables' name instead null. on updated column has date/time stamp of last modification of each table. know why table's names not listed?
see msdn.
object_name returns null on error or if caller not have permission view object.
or maybe nulls representing temporary tables.
the metadata function object_name database specific , uses information catalog tables in current database. if run query in different database (say master) names either wrong (because object_id may match different object in master database) or null. in order correct object name, query has executed in context of database interested.
Comments
Post a Comment