Friday, March 9, 2012

How to get recordset from only last SELECT stmt executed??

How to get recordset from only last SELECT stmt executed?

this is part of my code.. in T-Sql

Create proc some mySp
...
AS
...
set nocount on
if (@.SelUserID is null)
select 0
else if (@.SelUserID = @.userID)

select 1

else
begin

select * -- select a.
from dms_prsn_trx_log
where @.incNo = ult_incid_no and
prsn_trx_no = 10 and
trx_log_txt = @.logText
if (@.@.rowcount != 0)
set @.isForwardedByUser = 1
select 2 -- select b. I NEED This value.

end
set nocount off
GO

here it executes select a, b.
But, I want mySp return last executed select result. which is here "select 2"

I thought set nocount ON does that, but it doesn't.
How can I do?ANytime you select values without an assignment operator, they will be returned as part of the rowset. It sounds like you want to check for the existence of one rowset before selecting the second. So how about this:


if exists (select 1
from dms_prsn_trx_log
where @.incNo = ult_incid_no
and prsn_trx_no = 10
and trx_log_txt = @.logText)
begin
select b.
end
else
select a.
end|||Thank you it helps..
So, you means there is no such switch thing on off?
I thought it has...-.-

No comments:

Post a Comment