Forum Discussion

sdoscher's avatar
sdoscher
New Contributor III
4 years ago

SQL Server - Execute Snap

A statement like this works fine in SQL Server. How can I get something like this to work in the SQL Server - Execute Snap? There has to be a syntax issue that I have. Any help is appreciated.

DECLARE @sql AS varchar(max) = ‘This is a Test’
PRINT @sql

13 Replies

  • Hi @sdoscher,

    If I understood you correctly, you want to return something from SQL Execute snap?
    This syntax can help you “select ‘This is a Test’ as sql”. Put it in the SQL Execute Snap and see the results.

    BR,
    Marjan

  • sdoscher's avatar
    sdoscher
    New Contributor III

    Hi @marjan.karafiloski Yes, this works:
    select ‘This is a Test’ as sql.

    What I am ultimately trying to get to is for the Execute snap to execute dynamic SQL such as:
    DECLARE @sql AS varchar(max)
    SET @sql = ’
    select top 10 * from dbname.dbo.hc_table

    EXEC (@sql)

    Can the Execute snap do that?

    • marjan_karafilo's avatar
      marjan_karafilo
      Contributor

      Hi @sdoscher ,
      Yes, you can do that.

      Here is an image of how to set the query in Execute Snap:

      Here is an image of the output of the Execute Snap:

      BR,
      Marjan

      • sdoscher's avatar
        sdoscher
        New Contributor III

        Hmmm…that did not work for me. I talked to the SL admin and they said we are on
        SQL Server snap pack main11181. That is not the latest version, would that have anything to do with it? What version are you on?