; WITH bus AS (
SELECT database_name, machine_name, backup_finish_date, media_set_id, type,msdb.dbo.backupset.software_vendor_id,
msdb.dbo.backupset.user_name,
row_number () OVER(PARTITION BY database_name ORDER BY backup_finish_date DESC) AS rowno
FROM msdb.dbo.backupset
)
SELECT bus.machine_name AS ServerName, sdb.Name AS DatabaseName,
COALESCE(convert(varchar(23), bus.backup_finish_date), 'No backup') AS BackupTime ,
CASE bus.type
WHEN 'D' THEN 'Database'
WHEN 'L' THEN 'Log File'
WHEN 'I' THEN 'Differential'
END AS BackupType,software_vendor_id,user_name,
busf.physical_device_name AS Location
FROM sys.databases sdb
LEFT OUTER JOIN bus ON bus.database_name = sdb.name AND rowno <= 2
LEFT OUTER JOIN msdb.dbo.backupmediafamily busf ON busf.media_set_id = bus.media_set_id
WHERE database_id > 4
ORDER BY bus.machine_name
No comments:
Post a Comment