SELECT bus.machine_name AS ServerName, sdb.Name AS DatabaseName, COALESCE(CONVERT(DATETIME, MAX(bus.backup_finish_date)),'Backup Needed') AS NewBackUpTime, CASE WHEN type = 'D' THEN 'Database' WHEN type = 'L' THEN 'Log File' WHEN type = 'I' THEN 'Differential' END AS BackupType, busf.physical_device_name AS Location FROM sys.databases sdb RIGHT OUTER JOIN msdb.dbo.backupset bus ON bus.database_name = sdb.name RIGHT OUTER JOIN msdb.dbo.backupmediafamily busf ON busf.media_set_id = bus.media_set_id WHERE database_id > 4 GROUP BY sdb.Name, bus.type, bus.machine_name, busf.physical_device_name ORDER BY bus.machine_name GO
Above I have put my current code for checking if the databases have had a backup and at what time.
What I am trying to do now is get the old date and time record from the previous backup on the database.
So for example I backed up advertureworks last night I want that datetime to be shown next to my newbackuptime column. I've looked in the msdb.dbo.backupset and can see the old record in there. How to I take that and make it a column, I was thinking maybe a DISTINCT but that would probably only result me in having the 1 result.
I may not have explained this correctly but if you need to know anything else feel free to ask.
Regards
If this is helpful please mark it so. Also if this solved your problem mark as answer.