Syntax Error

  • The following query executes fine

    EXEC('SELECT a.* FROM OPENROWSET(''SQLOLEDB'', ''' + 'Trusted_connection=yes;' + 'Server=' + @Server_name + ''', ''SELECT * FROM msdb.dbo.sysdbmaintplan_history'') AS a')

    But if i try to use a where clause e.g. where activity = 'Backup Database', i'm receiving syntax errors. I'm messing up the quotes somehow. Can someone help me ?

  • Try this

    Select ('SELECT a.* FROM OPENROWSET(''SQLOLEDB'', ''Trusted_connection=yes;Server='

    + @@Servername

    +''', ''SELECT * FROM msdb.dbo.sysdbmaintplan_history where activity = ''''Backup Database'''' '') AS a')

    Exec('SELECT a.* FROM OPENROWSET(''SQLOLEDB'', ''Trusted_connection=yes;Server='

    + @@Servername

    +''', ''SELECT * FROM msdb.dbo.sysdbmaintplan_history where activity = ''''Backup Database'''' '') AS a')

  • Thanks numbers.

    That works fine.

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

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