Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

here is my query below:

SQL
declare @name varchar(50)
set @name='test'

select firstname as test from dbo.EmployeesNew

output:

   test
---------
1  a
2  b
3  c
4  d
5  e



i want alias column name is whichever value in @name.

thanks
Posted

1 solution

ok i got the solution.

we can write as

SQL
declare @name varchar(50)
declare @sql varchar(50)
set @name='test'
set @sql = 'select firstname as'+ @name+' from dbo.EmployeesNew'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900