SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Dynamic column headings
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

gidsy
Starting Member

1 Posts

Posted - 06/24/2012 :  19:39:51  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
2868 Posts

Posted - 06/24/2012 :  19:45:36  Show Profile  Reply with Quote
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

India
22461 Posts

Posted - 06/26/2012 :  05:26:37  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Are you generating Dynamic PIVOT?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000