我正在处理一小段代码。
代码在普通的ssms中运行良好,但当我将其放入邮寄步骤时似乎失败了?
它只是列出表格和计数,手动操作已经太久了。我正在努力创建乔布斯,以便在数据更新时,可以将计数邮寄给每台服务器的代表。
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'dbmail',
@recipients='random@needsthese.com',
@subject = 'those counts you want',
@body = 'these are count changes',
@execute_query_database = 'nbdb',
@query = 'CREATE TABLE #counts
(
table_name varchar(255),
row_count int
)
EXEC sp_MSForEachTable @command1='INSERT #counts (table_name, row_count)
SELECT ''?'', COUNT(*) FROM ?'
SELECT table_name, row_count FROM #counts ORDER BY table_name, row_count DESC'
将其修改为以下内容(只需在适当的位置添加引号)
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'dbmail',
@recipients='random@needsthese.com',
@subject = 'those counts you want',
@body = 'these are count changes',
@execute_query_database = 'nbdb',
@query = 'CREATE TABLE #counts
(
table_name varchar(255),
row_count int
)
EXEC sp_MSForEachTable @command1=''INSERT #counts (table_name, row_count)
SELECT ''?'', COUNT(*) FROM ?''
SELECT table_name, row_count FROM #counts ORDER BY table_name, row_count DESC'