Question : How can i return only last select statment from stored procedure

How can i return last select statment from following senario.
I wan to trap if sp fails or not from asp . But some how it only returns first select statment. and i ahve do rs.NextRecordset twice in order to get valur for @succeess.
How can i get only value for Select 'Success'= @Success, 'ErrMsg' = @ErrMsg  



CREATE PROCEDURE sp_Test
As

Declare @Success char(1)  
Declare @ErrMsg varchar(255)  
Set @Success = ''  
Set @ErrMsg = ''  

SELECT * FROM Table1
SELECT * FROM Table1

Set @Success = 'Y'  
Select 'Success'= @Success, 'ErrMsg' = @ErrMsg  
Return


   cn.ConnectionString = strConnection 'Application("SuperUserLogin")
   cn.Open()
   SQL  =  "exec sp_Test"
   Set rs = cn.Execute(SQL)
   fFlag=rs(0)            

Answer : How can i return only last select statment from stored procedure

Look into the OUTPUT parameters in SQL Stored Procedures. Essentially you can create your above procedure with an OUTPUT parameter as well this is your sproc with an output parameter added (I didn't change your proc at all, I am assuming this is just an example of a proc not your actual proc):

CREATE PROCEDURE sp_Test @@outputvar varchar(1)
As

Declare @Success char(1)  
Declare @ErrMsg varchar(255)  
Set @Success = ''  
Set @ErrMsg = ''  

SELECT * FROM Table1
SELECT * FROM Table1

Set @Success = 'Y'  
Select 'Success'= @Success, 'ErrMsg' = @ErrMsg  
Set @@outputvar = @success
Return

These two pages from ASP 101 will talk more about Stored Procs in General and give you two related code snippets of some ASP Code dealing with a stored proc that has an output parameter (you can actually set a variable in your vbscript to receive the output parameter through ADO). And then the other page will just talk about the stored procedure syntax and it also shows the stored proc referenced in the ASP code with an without the output parameter.

ASP Code: http://www.asp101.com/samples/viewasp.asp?file=storedprocs%2Easp    (if link broken you can get there from the SQL Code link below, just click on View ASP Code button)
SQL Code: http://www.asp101.com/samples/storedprocs.asp


Random Solutions  
 
programming4us programming4us