Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EVAL() counterpart in T-SQL

Status
Not open for further replies.

JackR

IS-IT--Management
Jun 7, 2001
10
0
0
US
Greetings all,

In VB - the EVAL() function can evaluate a literal string within an expression...

How would I do that in T-SQL..? Here's what I'm trying to do: I am updating a variable name that changes...initially @PSt=Phase1Start, then @PSt=Phase2Start, then @PSt=Phase3Start...and so on. Subsequently, we SELECT using @PSt which isn't working at all....??

How can I effect changes to literals then EVAL them at execution...??

Thanks
 
Use exec("a TSQL string"). exec() has two or three uses in T-SQL. One use is to interpret a string as a T-SQL statement and execute it. See Books Online.
Here is an example -

Code:
DECLARE @whichTableThisTime sysname
DECLARE @PSt VARCHAR(20)

SELECT @whichTableThisTime = 'BobsTable'
SELECT @PSt = '07/01/2002'

EXEC("SELECT * FROM " + @whichTableThisTime + " WHERE taskDate > '" + @PSt + "'")
 
Great - Thank you for your time..!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top