# Miscellaneous > Database Design >  TSQL equivalent of "Eval"?

## Doug Wendel

Hello all,

Does anyone know if there&#39;s a TSQL function that acts like a JavaScript eval? What I&#39;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?

----------


## SteveNom

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

----------


## rmiao

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.

----------


## SteveNom

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?

----------


## rmiao

Didn't try it before.

----------

