Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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 server 在SQL查询中返回@@rowcount结果_Sql Server_Rowcount_Raiserror - Fatal编程技术网

Sql server 在SQL查询中返回@@rowcount结果

Sql server 在SQL查询中返回@@rowcount结果,sql-server,rowcount,raiserror,Sql Server,Rowcount,Raiserror,我想找出错误如果存在,然后打印匹配的行数。但这不起作用。请帮忙 if exists (select * from [rto] a inner join rt b on a.NUM=b.TABLE_NAME where a.START_YEAR between b.YEAR_START and b.YEAR_STOP) Raiserror ('Matched recs found',16,1) print 'There are' + cast(@

我想找出错误
如果存在
,然后打印匹配的行数。但这不起作用。请帮忙

if exists (select * from [rto] a
     inner join rt b
     on a.NUM=b.TABLE_NAME
     where a.START_YEAR between b.YEAR_START and b.YEAR_STOP)
     Raiserror ('Matched recs found',16,1)
     print 'There are' +  cast(@@rowcount as varchar(20)) + 'matched rows'

您错过了
开始
结束

if exists (select * from [rto] a
    inner join rt b
    on a.NUM=b.TABLE_NAME
    where a.START_YEAR between b.YEAR_START and b.YEAR_STOP)
BEGIN
    Raiserror ('Matched recs found',16,1)
    print 'There are ' +  cast(@@rowcount as varchar(20)) + ' matched rows'
END

这是您原始帖子的替代方案…不确定您是否有特定要求,但这应该会得到您想要的错误输出:

DECLARE @rowcount INT
SET @rowcount = (select COUNT(*) from [rto] a
    inner join rt b
    on a.NUM=b.TABLE_NAME
    where a.START_YEAR between b.YEAR_START and b.YEAR_STOP)
IF @rowcount > 0
BEGIN
    Raiserror ('Matched recs found',16,1)
    print 'There are ' +  cast(@rowcount as varchar(20)) + ' matched rows'
END

谢谢,但它返回零,但我可以看到有匹配的记录。