WITH LastBackUp AS
(
    SELECT  bs.database_name,
            bs.backup_size,
            bs.backup_start_date,
            bmf.physical_device_name,
            bs.[name],
            Position = ROW_NUMBER() OVER( PARTITION BY bs.database_name ORDER BY bs.backup_start_date DESC )
    FROM  msdb.dbo.backupmediafamily bmf
        JOIN msdb.dbo.backupmediaset bms ON bmf.media_set_id = bms.media_set_id
        JOIN msdb.dbo.backupset bs ON bms.media_set_id = bs.media_set_id
    WHERE   bs.[type] = 'D'
    AND bs.is_copy_only = 0
)
,lastBkpYesterday AS (
    SELECT  bs.database_name,
            bs.backup_size,
            bs.backup_start_date,
            bmf.physical_device_name,
            bs.[name],
            Position = ROW_NUMBER() OVER( PARTITION BY bs.database_name ORDER BY bs.backup_start_date DESC )
    FROM  msdb.dbo.backupmediafamily bmf
        JOIN msdb.dbo.backupmediaset bms ON bmf.media_set_id = bms.media_set_id
        JOIN msdb.dbo.backupset bs ON bms.media_set_id = bs.media_set_id
    WHERE   bs.[type] = 'D'
    AND bs.is_copy_only = 0
    AND bs.backup_start_date < DATEADD(DAY, -1, CAST(CURRENT_TIMESTAMP AS DATE))
)
SELECT 
    sd.name AS [Database],
    REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, lb.backup_size / 1048576), 1),',',''''),'.00','') AS [backup size MB],
    lb.backup_start_date AS [Last Full DB Backup Date],
    lb.physical_device_name AS [Last Backup File Location],
    lby.backup_start_date AS [Previous Full DB Backup Date],
    lb.physical_device_name AS [Previous Backup File Location],
    lb.[name] AS [last backup name],
    lby.[name] AS [Previous last backup name]
FROM sys.databases AS sd
    LEFT JOIN LastBackUp AS lb ON sd.name = lb.database_name AND lb.Position = 1
    LEFT JOIN lastBkpYesterday lby ON sd.name=lby.database_name and lby.Position=1
ORDER BY [Database];

