我希望raiserror if exists
然后print
匹配的行数。但这不起作用。请帮忙 。
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'
答案 0 :(得分:0)
您错过了BEGIN
和END
:
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
答案 1 :(得分:0)
这是您原始帖子的替代方案......不确定您是否有特定要求,但这可以为您提供所需的错误输出:
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