如何清除/重置存储过程中的结果

时间:2012-01-20 14:19:04

标签: sql-server sql-server-2008 tsql

我正在运行一个应该生成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

2 个答案:

答案 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');