I'm using the following code to determine the last time a database was backed up:
SELECT @@ServerName as HostServerName ,bus.server_name AS BUSservername ,sdb.Name AS DatabaseName ,COALESCE(CONVERT(VARCHAR(12), MAX(bus.backup_finish_date), 101), '-') AS LastBackUpTime FROM sys.sysdatabases sdb LEFT OUTER JOIN msdb.dbo.backupset bus ON bus.database_name = sdb.name WHERE bus.backup_start_date >= DATEADD(DAY, DATEDIFF(DAY, 1, GETDATE()), 0) -- Previous day at midnight. AND bus.backup_start_date < DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0) -- Today at midnight. GROUP BY sdb.Name ,bus.server_name
And it appears to show the data I'm looking for, but if I run this code on a development server, for example, it shows its corresponding production server as the
I'm trying to understand why it's showing a production server' name and not itself. I may not be understanding how the backupset table is getting its value.
I know I can use
@@ServerName for that value but I'm not sure if that is correct way to get that value.
Below is a screenshot of my results with the server names obviously blacked out: