Hello,
I'm trying to concatenate a variable to a sql statement that creates a pivot table. This statement is givig me an error
Select ship_from,
'Jan-'+@cyear=sum(case when invoice_dt >= '01/01/' + @cyear + ' 00:00:00:000' and invoice_dt< '01/31/' + @cyear + ' 23:59:59:999' then quantity else 0 end),
Feb=sum(case when invoice_dt >= '02/01/' + @cyear + ' 00:00:00:000' and invoice_dt< '02/29/' + @cyear + ' 23:59:59:999' then quantity else 0 end),
Mar=sum(case when invoice_dt >= '03/01/' + @cyear + ' 00:00:00:000' and invoice_dt< '03/31/' + @cyear + ' 23:59:59:999' then quantity else 0 end)
From my Table
group by ship_from
Can you give me an idea how I could make this string 'Jan-'+@cyear become the column name of my pivot table?
Thank you much.
I'm trying to concatenate a variable to a sql statement that creates a pivot table. This statement is givig me an error
Select ship_from,
'Jan-'+@cyear=sum(case when invoice_dt >= '01/01/' + @cyear + ' 00:00:00:000' and invoice_dt< '01/31/' + @cyear + ' 23:59:59:999' then quantity else 0 end),
Feb=sum(case when invoice_dt >= '02/01/' + @cyear + ' 00:00:00:000' and invoice_dt< '02/29/' + @cyear + ' 23:59:59:999' then quantity else 0 end),
Mar=sum(case when invoice_dt >= '03/01/' + @cyear + ' 00:00:00:000' and invoice_dt< '03/31/' + @cyear + ' 23:59:59:999' then quantity else 0 end)
From my Table
group by ship_from
Can you give me an idea how I could make this string 'Jan-'+@cyear become the column name of my pivot table?
Thank you much.