我有一个简化为以下代码的存储过程:
SET NOCOUNT ON
DECLARE @count INT
DECLARE @temp TABLE
INSERT INTO @temp
SELECT @count = count(*) FROM @temp
DECLARE [cursor] FOR SELECT id FROM @temp
OPEN [cursor] FETCH NEXT FROM [cursor] INTO @id WHILE @@fetch_status = 0
BEGIN
exec anoterStoredProc @id
FETCH NEXT FROM [cursor] INTO @id
END
CLOSE [cursor]
DEALLOCATE [cursor]
SET NOCOUNT OFF
RETURN @count
但ExecuteNonQuery()
仍然返回 -1!
我可以使用select @count
但ExecuteScalar()
想了解为什么我的代码不起作用。
似乎NOCOUNT OFF
不会重置服务器行为,并且NOCOUNT ON
仍然在原地。