• DECLARE @string1 NVARCHAR(1000)

    DECLARE @Output NVARCHAR(15)

    SET @String1 = 'select @item = MAX(backup_set_id)

    FROM ['+@server_name+'].msdb.dbo.backupset

    WHERE database_name = '''+@db+''' AND type = ''D'''

    exec sp_executesql @string1, N'@item nvarchar(15) OUTPUT', @item = @output OUTPUT

    select @output

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass