Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql sp_send_dbmail错误_Sql_Tsql_Sql Server 2005 - Fatal编程技术网

Sql sp_send_dbmail错误

Sql sp_send_dbmail错误,sql,tsql,sql-server-2005,Sql,Tsql,Sql Server 2005,如何在sp\u send\u dbmail中的@query参数中传递多个查询 例如: select count(*) from TableA IF count(*)/ @@rowcount = 0 Exec sp_send_dbmail @profile_name = xx, @recipients = 'xx@abc.com',@subject = 'Test', @body= ' No rows'; IF count(*)/ @@rowcount > 0 Exec sp_send_

如何在
sp\u send\u dbmail
中的
@query参数中传递多个查询

例如:

select count(*) from TableA
IF count(*)/ @@rowcount = 0  
Exec sp_send_dbmail @profile_name = xx, @recipients = 'xx@abc.com',@subject = 'Test', @body= ' No rows';
IF count(*)/ @@rowcount > 0
Exec sp_send_dbmail @profile_name = xx, @recipients = 'xx@abc.com',@subject = 'Test', 
@body= ' xx rows';

我没有收到任何错误消息,但它在第一个select语句后停止。

当您从表A执行
select count(*)时,您没有将值保留在某个位置,它只执行并返回查询结果。这就是为什么
if
语句没有触发的原因。你可以这样做:

DECLARE @c AS int
SET @c = (select count(*) from TableA)

IF @c = 0
Exec sp_send_dbmail @profile_name = xx, @recipients = 'xx@abc.com',@subject = 'Test', @body= 'No rows';

IF @c > 0
Exec sp_send_dbmail @profile_name = xx, @recipients = 'xx@abc.com',@subject = 'Test', 
@body= ' xx rows';
虽然我对将这种逻辑放在SQL端有些保留。但因为我不知道你是如何使用它的,所以现在应该可以用了