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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

assign a variable

Status
Not open for further replies.

CliveW

Technical User
Aug 19, 2002
36
GB
Posted on behalf of the programmer


Stupid but Annoying

I'm a fox developer and have been tasked to use SQL Server 2000.
In fox you can assign a variable with '2+3' then run this, for example
jnk = '3+2'
? EVALUATE(jnk)
which results in 5.
I want to do the same in SQL, but can't. I have tried the help and quite a
few guesses and am now losing the will ................would be very grateful for
any help.

 
You will need to use dynamic SQL. For your current example

declare @sql varchar(100)
set @sql = 'select 2+3'
execute @sql

Basically, you can construct a select statement (or some other SQL statement) in a string and execute the string to get the results. There is another method available using sp_executesql system procedure which you can check out in the help. RT
 
Thanks for the reply the programmer is very happy at last.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top