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 |
|
TRACEYSQL
Aged Yak Warrior
594 Posts |
Posted - 2007-01-16 : 14:30:07
|
| I have a tabledeclare @min_date nvarchar(15), @max_date nvarchar(15)select @min_date = min(convert(char(10),last_backup_date,101)) from systemadm.db_backup where last_backup_date is not nullselect @max_date = max(convert(char(10),last_backup_date,101)) from systemadm.db_backup where last_backup_date is not nullprint @min_dateprint @max_dateSELECT servername, dbname, last_backup_path, SUM(CASE WHEN convert(char(10),last_backup_date,101) = '01/14/2007' THEN 1 ELSE 0 END) AS 'jan 14', SUM(CASE WHEN convert(char(10),last_backup_date,101) = '01/15/2007' THEN 1 ELSE 0 END) AS 'jan 15', SUM(CASE WHEN convert(char(10),last_backup_date,101) = '01/16/2007' THEN 1 ELSE 0 END) AS 'jan 16'FROM systemadm.db_backupGROUP BY servername, dbname, last_backup_pathPrint out correctly servername dbname jan 14 jan 15 jan 16 SQL1 UNIA 1 0 1SQL1 UNIB 1 1 1Is there any way i can do the sum case part but past in the @min_date and @max_date so that i do not code entire calendar into this.Hmmm |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|
|