Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Dynamic column headings

Author  Topic 

gidsy
Starting Member

1 Post

Posted - 2012-06-24 : 19:39:51
Hi,

Is there a way of having a variable as a column heading...e.g.

set @week = 'Week 1'

select 'x' as @week
from etc

Result:

Week 1
x

Thanks

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-06-24 : 19:45:36
Not without using Dynamic SQL. Try to avoid dynamic sql when possible.

declare @sql varchar(1000) -- or whatever length is appropriate

SET @sql = ' SELECT ''x'' as '+@week +
' from etc '

EXEC(@sql)


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-06-26 : 05:26:37
Are you generating Dynamic PIVOT?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -