|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, July 13, 2012 6:54 AM
Points: 4,
Visits: 101
|
|
| What about adding a column thats adds "Number of Days Since Last Backup" in addition to the "Started" and "Finished" columns?
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, March 18, 2013 5:11 AM
Points: 139,
Visits: 143
|
|
Normally in production the number of days since last backup should all be 0 as the backups are critical. However should you need the number of days just change the SET @tblHTML in the stored proc to include a datediff column. I have done it and pasted the code below this message. Notice that I have included a case statement and also cast it to a varchar. This is just to keep the listing clean. As if there is no backup the datediff will return 39967. ------------------------------------- SET @tableHTML = N''+ N''+ N'| Database Backup Status Report | ' + N'| AS OF '+convert(varchar(50),getdate(),101) + ' '+convert(varchar(50),getdate(),108)+N' | '+ N' '+ N'' + N' | DBName | '+ N'Backup Type | ' + N'Backup File | '+ N'Backup Size(bytes) | '+ N'Age(Days) | ' + N'Started | ' + N'Finished | ' + N'Time(mins) | ' + N' ' + CAST ( ( SELECT "td/@align"='left' ,td = bks.DBName, '', "td/@align"='left' ,td = bks.BackupType, '', "td/@align"='left' ,td = bks.BackupFile, '', "td/@align"='right',td = bks.BackupSize, '', "td/@align"='right',td = case when bks.BackupType<>'---NONE---' then convert(varchar(4),dateDiff(d,BackupStartDate_dt,getdate())) else '' end, '', "td/@align"='left' ,td = bks.BackupStartDate, '', "td/@align"='left' ,td = bks.BackupEndDate, '', "td/@align"='right',td = bks.BackupDuration FROM @Tbl as BKS ORDER BY BKS.DBname,BKS.BackupStartDate_dt FOR XML PATH('tr'), TYPE ) AS NVARCHAR(MAX) ) + N' ' ;
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, March 18, 2013 5:11 AM
Points: 139,
Visits: 143
|
|
 Sorry the pasting of code did not seem to work too well, I am trying to attach the code within the IFCode Shortcuts, hope it works
SET @tableHTML = N'<style type="text/css">'+ N'.h1 {font-family: Arial, verdana;font-size:16px;border:0px;background-color:white;} '+ N'.h2 {font-family: Arial, verdana;font-size:12px;border:0px;background-color:white;} '+ N'body {font-family: Arial, verdana;} '+ N'table{font-size:8px; border-collapse:collapse;} '+ N'td{background-color:#F1F1F1; border:1px solid black; padding:3px;} '+ N'th{background-color:#99CCFF;}'+ N'</style>'+ N'<table border="0">'+ N'<tr><td class="h1">Database Backup Status Report</td></tr>' + N'<tr><td class="h2">AS OF '+convert(varchar(50),getdate(),101) + ' '+convert(varchar(50),getdate(),108)+N'</td></tr>'+ N'</table>'+ N'<table border="1">' + N'<tr> <th>DBName</th>'+ N'<th>Backup Type</th>' + N'<th>Backup File</th>'+ N'<th>Backup Size(bytes)</th>'+ N'<th>Age(Days)</th>' + N'<th>Started</th>' + N'<th>Finished</th>' + N'<th>Time(mins)</th>' + N'</tr>' + CAST ( ( SELECT "td/@align"='left' ,td = bks.DBName, '', "td/@align"='left' ,td = bks.BackupType, '', "td/@align"='left' ,td = bks.BackupFile, '', "td/@align"='right',td = bks.BackupSize, '', "td/@align"='right',td = case when bks.BackupType<>'---NONE---' then convert(varchar(4),dateDiff(d,BackupStartDate_dt,getdate())) else '' end, '', "td/@align"='left' ,td = bks.BackupStartDate, '', "td/@align"='left' ,td = bks.BackupEndDate, '', "td/@align"='right',td = bks.BackupDuration FROM @Tbl as BKS ORDER BY BKS.DBname,BKS.BackupStartDate_dt FOR XML PATH('tr'), TYPE ) AS NVARCHAR(MAX) ) + N'</table>' ;
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, July 13, 2012 6:54 AM
Points: 4,
Visits: 101
|
|
| Does this also work for SQL 2008? If not can we get a version that does?
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, March 18, 2013 5:11 AM
Points: 139,
Visits: 143
|
|
| Hi I do not currently have access to a SQL 2008 server. I would love it if someone who has SQL 2008 checks the code to see if it works or breaks and or tweaks the code. If not I shall surely do so myself the moment I have an SQL 2008 server to work with.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Sunday, May 19, 2013 8:09 AM
Points: 1,558,
Visits: 1,396
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, March 18, 2013 5:11 AM
Points: 139,
Visits: 143
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Today @ 2:38 PM
Points: 4,
Visits: 109
|
|
doesnt work for me guys. Ran this in 2008 and get the following error
Msg 1087, Level 15, State 2, Line 32 Must declare the table variable "@Tbl".
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Sunday, May 19, 2013 8:09 AM
Points: 1,558,
Visits: 1,396
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 12:21 PM
Points: 1,
Visits: 52
|
|
I am trying to use this scripts on SQL Server 2008 R2 box but not working.
Do I need to change any part of the scripts. Please advise. Thank you, Haider
|
|
|
|