Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2007-01-04 : 09:41:32
|
writes "Is there any way to return multiple results from a stored procedure in sql server 2000 i.eCan i use two EXEC stmt's within one single stored procedure.I have tried two ways.Using first way i am able to return resultset as well as count. The reason is the 2nd query inside first method is static. But i need the second query to be built dynamically.That is what i tried using second method but failed to do it.here is the codemethod-1========create PROCEDURE TEST_SP(@N INT OUT)ASDECLARE @SQL VARCHAR(100)BEGIN SET @SQL='SELECT * FROM DEPT' EXEC (@SQL) SELECT @N=COUNT(*) FROM DEPTENDsample execution of first method----------------------------------- DECLARE @N INTEXEC TEST_SP @N OUTPUT SELECT @Nmethod-2=========create PROCEDURE TEST_SP(@N INT OUT)ASdECLARE @S1 VARCHAR(100)dECLARE @S2 VARCHAR(100)BEGIN SET @S1='SELECT * FROM DEPT' EXEC (@S1) set @s2='SELECT @N=COUNT(*) FROM DEPT' exec (@s2)ENDsample execution of second method----------------------------------- DECLARE @N INTEXEC TEST_SP @N OUTPUT SELECT @NError:Server: Msg 137, Level 15, State 1, Line 1Must declare the variable '@N'.Any answers will be appreciable.Thanks in advance,Regards,Raj" |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-01-04 : 10:13:55
|
But I think what you need isSELECT * FROM DEPTSELECT @@ROWCOUNTMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|