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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Example:
Declare @TID int
Declare @SID int
Select @TID = TransactionID, @SID = StockpileID from Transactions where TransactionID = 41285
Select @TID, @SID
sorry sree_ven , I havn't refresh the page before posting
No worries :-)
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