【发布时间】:2011-03-15 06:19:21
【问题描述】:
我有一个插入语句:
insert into parentTbl
select firstId, secondId, thirdId, dateTm
from importTbl
where codeId = @codeIdParam
我需要可靠地确定该插入是否插入了任何内容。理想情况下,我想将 @insertedCount 变量设置为插入的行数,即使是 0。
我目前正在使用:
set @insertedCount = @@ROWCOUNT
但这似乎只获得了最后插入的行数 - 问题是如果 INSERT SELECT 语句没有插入任何内容,@@ROWCOUNT 不会返回 0。
【问题讨论】:
-
您的插入语句是否位于循环或游标中?
标签: tsql select insert rowcount