我正在运行一个应该生成scope_id
的存储过程,但是返回了许多结果集。
此代码:
INSERT INTO ..
SELECT @AddedID = SCOPE_INDENTITY()
EXEC NewSP --Returns a Scope_Identity also
我如何做到这一点(清除结果并重新开始):
INSERT INTO..
SELECT @AddedID = SCOPE_INDENTITY()
EXEC NewSP --Returns a Scope_Identity also
CLEAR_ALL_RESULTS -- Need to be able to clear all the results here
SELECT @AddedID as AddedID --Only return this results now after clearing all prior
答案 0 :(得分:0)
您可以随时使用output parameter。
答案 1 :(得分:0)
也许使用“输出”是个好主意:)(msdn)
create table #ttable
(
id int primary key identity,
someText nvarchar(20)
)
Go
Insert Into #ttable (someText)
Output inserted.id
Values ('Some text');