Forum Discussion

Jonathan_Hart's avatar
4 years ago
Solved

IF EXIST statement for a JDBC Alert

Hello, I'm trying to setup an alert that runs a query against an  MSSQL DB and in a couple of cases the DB name is different. The intial thought was that I could add IFEXIST (DB name que...
  • Jonathan_Hart's avatar
    4 years ago
    2 hours ago, Vitor Santos said:

    Not sure if I'm understanding it correctly but, I believe if it returns an error it'll abort the operation & return you the exception.
    My suggestion is to use try, catch (via groovy instead)... to predict those possible scenario(s) & don't abort the script without following the remaining operations.

    Not sure if this will help you, but, just a suggestion :)/emoticons/smile@2x.png 2x" title=":)" width="20" /> 

    Thanks for the response Vitor, 

    Did a little more digging and found the best way to do it (in this case, not necessarily the best way) was to add DECLARE @SQL NVARCHAR(MAX); and then print @SQL at the end so: 

    --PRINT @SQL
    EXECUTE sp_executesql @SQL
    END

    This then allowed me to use multiple DB names and it wouldn't error when the DB didn't exist for different server.

    Thanks
    Jonny