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.
Author |
Topic |
Vack
Aged Yak Warrior
530 Posts |
Posted - 2014-11-14 : 11:12:45
|
Is there a way I make the column date the current date? select ISNULL(SUM(CASE WHEN req_ship_dt = GETDATE() THEN TotalSales END), 0) AS day from QIVSalesbyDAY q So depending on the day I run the script it will make the column name the current date? I've triedselect ISNULL(SUM(CASE WHEN req_ship_dt = GETDATE() THEN TotalSales END), 0) AS getdate() from QIVSalesbyDAY q |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-11-14 : 11:27:54
|
use dynamic sql:declare @sql nvarchar(4000) ='select ISNULL(SUM(CASE WHEN req_ship_dt = GETDATE() THEN TotalSales END), 0) AS ['+ cast(getdate() as varchar(20))+ '] from QIVSalesbyDAY q'exec sp_executesql @sql |
|
|
Kristen
Test
22859 Posts |
Posted - 2014-11-16 : 03:57:36
|
[code]req_ship_dt = GETDATE()[/code]GetDate() returned the current date AND time, so it is unlikely that test is ever going to be true.You might need[code]req_ship_dt = CONVERT(date, GETDATE())[/code] |
|
|
|
|
|