Here's my statement below. What I'm trying to get is joining the name column in master.sys.databases with a sub query for the database name, file location and backup start date from the MSDB database. The reason for this, if a new database has never been backed up, It should be returning as a NULL value, which is my goal. However, I'm getting multiple results for the backups. Any help or suggestions would be greatly appreciated. select CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server,a.name,File_Location=b.physical_device_name,backup_start_date=max(backup_start_date) from master.sys.databases a left join (select c.database_name,backup_start_date=max(backup_start_date),b.physical_device_name from msdb.dbo.backupmediafamily b join msdb.dbo.backupset c on c.media_set_id=c.backup_set_id where c.type='D' group by c.database_name,b.physical_device_name) b on a.name=b.database_name where a.name not in ('tempdb','model') and a.name not in ('msdb','master') and a.state_desc = 'ONLINE' group by a.name,b.backup_start_date,b.physical_device_name order by b.backup_start_date desc
↧