select CONVERT(varchar(50), (DATEADD(dd, @@DATEFIRST - DATEPART(dw, datecol), datecoll)), 101)
gives first date but how could i assign it as week1 in
sum(case when datepart(wk,datecol)=1 then count1 else 0 end) week1,
am trying to put first date as column header.. ist possible?
Depending on the way you use to run this query, it is possible to use a variable as a column name.
Try inserting your query as a value of a variable and executing it with the
EXEC command.
Declare @week1 as varchar(10)
Declare @SQL as varchar(1000)
set @week1 = 'ABC'
set @SQL = 'select ColumnA as ' + @week1 + ' from tableA '
Exec(@SQL)
adam_k
Practically a Posting Shark
803 posts since Jun 2011
Reputation Points: 256
Solved Threads: 149