Link to home
Start Free TrialLog in
Avatar of countrymeister
countrymeister

asked on

SQL syntax

I have a few variables declared, what I need is to set the variables to some values from a single select from a temp table.

example
declare
@Action varchar(30)
, @CurrentUserID varchar(40)
,@ID int
,@VersionNumber
 
I would like to do something like this
 SELECT @Action , @CurrentUserID = OpsAction, OpsUser from #tmpGroup where ID= @ID and VersionNumber = @CurrentVersionNo

Is there a way to set multiple values from a single select
I know this works
SELECT @Action = OpsAction from #tmpGroup where ID= @ID and VersionNumber = @CurrentVersionNo

but want to avoid repeating the select
ASKER CERTIFIED SOLUTION
Avatar of Sreedhar Vengala
Sreedhar Vengala
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pratima
Yes it is possible
you can set multiple values from a single select like below
change this as per your requirment @CurrentUserID = OpsAction

SELECT @Action= OpsAction , @CurrentUserID = OpsAction, OpsUser from #tmpGroup where ID= @ID and VersionNumber = @CurrentVersionNo
Example:

 
 

Declare @TID int 
Declare @SID int 
Select @TID = TransactionID, @SID = StockpileID from Transactions where TransactionID = 41285 
 
Select @TID, @SID 

Open in new window

sorry sree_ven , I havn't refresh the page before posting
No worries :-)