Results 1 to 5 of 5

Thread: TSQL equivalent of "Eval"?

  1. #1
    Doug Wendel Guest

    TSQL equivalent of "Eval"?


    Hello all,

    Does anyone know if there's a TSQL function that acts like a JavaScript eval? What I'd like to do is declare some of my SQL code as text variables and then use that code later by referencing that variable. Is there a way to do this?

  2. #2
    Join Date
    Jan 2008
    Posts
    2

    TSQL equivalent of "Eval"?

    I had the same problem. I found this solution:

    Declare @SQL as varchar(1000);

    SET @SQL = 'DECLARE Transfers_Cursor CURSOR FOR
    SELECT * FROM tblTransferWorksheet WHERE Trans_ID IN (' + @Trans_IDs + ')'

    EXEC (@SQL)

    Fab

  3. #3
    Join Date
    Sep 2002
    Posts
    5,938
    Or just

    exec ('DECLARE Transfers_Cursor CURSOR FOR
    SELECT * FROM tblTransferWorksheet WHERE Trans_ID IN (' + @Trans_IDs + ')' )

    It's dynamic sql in sql server term.

  4. #4
    Join Date
    Jan 2008
    Posts
    2
    Do you know if SQL that is executed this way using Exec, will count as part of series of Transactions if enclosed within a BEGIN Transaction and Commit/rollback transaction?

  5. #5
    Join Date
    Sep 2002
    Posts
    5,938
    Didn't try it before.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •