Want to show Dynamic column name in SQL SERVER 2008

Jul 5 2012 7:57 AM
Hello All

I have a problem
I want to show Column name like 'Jan-2010','Feb-2010' and so on.

declare @Year int = 2012 
declare @a varchar(20) 
set @a= CAST('jan-' as varchar(20))+ Cast(@Year as Varchar(20)) 
 print @a 
select ColumnName as  @a

The 'Jan-','Feb-','Mar-' are hard coded, but year should  come dynamically.  
and column name should appear like 'Jan-2010','Feb-2010' if Year is 2010,
if Year is 2011, it should show like 'Jan-2011','Feb-2011' and so on.

Pls help as soon as possible.
Thanks in Advance.
Regards
Anurag


Answers (2)