Thursday, March 29, 2012

Calling Stored Procedure to get results into another stored procedure

I have a complex stored procedure which in the end, has a select statement and returns a number of rows... such as: Select * from Temp_Table.

I want to access these records in another stored procedure and do some maniulation on the rows, such as sum them or perform other calculations.

How can I access these rows via a select statement or just insert them into a temp table in the 2nd stored procedure?

Thanks so much

Stored Procedures can't be referenced in the FROM clause.

But you can use them as input to an INSERT statement.

Code Snippet

createtable #t1(a int, b int, c int)

insertinto #t1

exec dbo.myproc

|||

One way to do this is to create the temp table in the calling procedure and then load it in the called procedure:

ifobject_id('spy')isnotnulldropproc spy

go

createproc spy as

insert #x values(1)

return

go

ifobject_id('spx')isnotnulldropproc spx

go

createproc spx as

createtable #x(x1 int)

exec spy

select*from #x

return

go

exec spx

Ron Rice

|||

Thanks for the response...

I converted the Stored Proc to an inline table function. This seems to do the trick.

Tks

No comments:

Post a Comment