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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 display data across page

Author  Topic 

TRACEYSQL
Aged Yak Warrior

594 Posts

Posted - 2007-01-16 : 14:30:07
I have a table



declare @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 null
select @max_date = max(convert(char(10),last_backup_date,101)) from systemadm.db_backup where last_backup_date is not null
print @min_date
print @max_date



SELECT
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_backup

GROUP BY servername, dbname, last_backup_path

Print out correctly



servername dbname jan 14 jan 15 jan 16
SQL1 UNIA 1 0 1
SQL1 UNIB 1 1 1


Is 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

Posted - 2007-01-16 : 14:41:32
I would say a left join from a calendar table should work nicely



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -