Reputation: 123
I have declared one variable in SQL Server:
declare @InsuredRaceEthnicId int
And assigning value to it like this:
select @InsuredRaceEthnicId = MAX(InsuredRaceEthnicId)
from dbo.InsuredRaceEthnic with (nolock)
It's giving me value with no column name but I need a column name.
Upvotes: 1
Views: 2437
Reputation: 34774
You can alias a variable the same way you'd alias a column:
DECLARE @test VARCHAR(50) = '1222'
SELECT @test AS Test
Your SELECT
statement shouldn't be returning anything, it's just setting the value of the variable, you could subsequently SELECT
/PRINT
the variable if so desired.
Upvotes: 1