|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 2:24 AM
Points: 1,871,
Visits: 2,692
|
|
Comments posted to this topic are about the item Database State and Backup Information
---------------------------------------------- Msg 8134, Level 16, State 1, Line 1 Divide by zero error encountered.
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Saturday, May 18, 2013 5:49 AM
Points: 202,
Visits: 1,043
|
|
Good work!
but you seems to use extra(not required) parenthesis. might be good, but affected readability a bit. (just general comments not to take it serious).
2ndly, the code segment
Convert(real(256), MAX(u.backup_size), 101),'NA'))/1024)/1024 may result into truncation of data... !! not specific to this problem but i am trying to raise a general warning here that the code segment may have this in addition
Convert(real(256), MAX(u.backup_size), 101),'NA'))/1024.0000)/1024.0000 as you may know that Sql Server may return results in INT data type rather than in fractional (required format), and the CONVERT function will certainly would receive already truncated data (+ not rounded data) and consequently, u may get fractional truncation summation error in matter of summation of large number of records.
I hope so, u may get what i intended for.
Please don't forget to comment over it.
& Thanks
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 6:52 AM
Points: 389,
Visits: 497
|
|
You may want to consider differentiating between types of backups. You may have log backups running fine but no full backups taking place. Also I would consider including databases which do not have records in msdb.dbo.backupset to highlight any database for which no backups have taken place.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 2:24 AM
Points: 1,871,
Visits: 2,692
|
|
Noted, and thank you for the feedback.
SELECT t.name as [DB Name], t.user_access_desc as [Access State], t.state_desc as [Online/Offline], ((SELECT (CASE t.is_in_standby WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'Other' END))) as [In Standby], (COALESCE(Convert(datetime, MAX(u.backup_finish_date), 101),'Not Yet Taken')) as [Last BackUp Taken], ROUND((((COALESCE(Convert(real(256), MAX(u.backup_size), 101),'NA'))/1024.000)/1024.000),3) as [Backup Size in MB], (COALESCE(Convert(varchar(10),MAX(datediff(d, getdate(), u.backup_finish_date))),101)) as [Days since Backup], (COALESCE(Convert(varchar(12), MAX(u.type), 101),'NA')) as [Backup_type], (COALESCE(Convert(varchar(12), MAX(u.user_name), 101),'NA')) as [User Name] FROM SYS.DATABASES t INNER JOIN msdb.dbo.BACKUPSET u ON t.name = u.database_name GROUP BY t.Name,t.is_in_standby, t.user_access_desc, t.state_desc ORDER BY t.Name
---------------------------------------------- Msg 8134, Level 16, State 1, Line 1 Divide by zero error encountered.
|
|
|
|