Reputation: 482
I'd like to simultaneously do two things in an MSSQL query:
select @myvar = colName from tableName
select colName as [myCol] from tableName
I've tried these things:
select @myvar = colName as [myCol] from tableName
select @myvar = (colName as [myCol]) from tableName
select (@myvar = colName) as [myCol] from tableName
If this is possible, how can it be accomplished?
Upvotes: 0
Views: 2611
Reputation: 15816
A select
can either assign values to variables or return column values, but not both.
In some cases, e.g. when using select
to provide data to an insert
, an output clause may be useful. A tool well worth having in your pocket as it provides access to identity values from insert
and both before and after values when used with update
.
Upvotes: 3