Variable within a variable when using dbmail (@subject)

  • This might be simple, but i can't seem to get it right. I imagine its with the quotes... the @subject isn't working....

    help!

    SET NOCOUNT ON

    DECLARE @database_profile_name varchar(35)

    , @dbname varchar (35)

    set @dbname = 'TESTDB'

    exec msdb.dbo.usp_GetMailProfile @database_profile_name output

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = @database_profile_name

    , @recipients = 'me@me.com'

    , @subject = 'SUCCESS : Restore '' + @DBNAME + ''completed'

    , @query = 'SET NOCOUNT ON

    select top 1 restore_date as LAST_RESTORE from msdb.dbo.restorehistory

    where destination_database_name = ''' + @DBNAME + '''

    order by restore_date desc'

    the error is saying syntax with the '+' is wrong

  • ahhh... i think i got it... can't concatenate inside the variable of a SP, or function.... i guess i'll just wait for any confirmations....

    have to set a new variable with the @cmd and then call the variable in the @subject = @cmd...

  • knight (6/26/2009)


    ahhh... i think i got it... can't concatenate inside the variable of a SP, or function.... i guess i'll just wait for any confirmations....

    have to set a new variable with the @cmd and then call the variable in the @subject = @cmd...

    Correct. You need to complete the concatenation outside the call to dbmail.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply