Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Evaluating a parameter's value dynamically

Author  Topic 

Billkamm
Posting Yak Master

124 Posts

Posted - 2006-01-25 : 15:58:52
Hi, I'm creating a dynamic SQL statement that is similiar to this:

EXEC('IF @' + @current_column + ' (SELECT ' + + @current_column etc...

I'm basically looping through a large list of parameters that correspond to column names. However, since SQL Server treats EXEC() as its own scope when it gets to what "@' + @current_column" evaluates to it says the parameter must be declared.

Is there a way to convert "@' + @current_column " into the actual value of the parameter?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-25 : 16:14:11
try sp_executesql

----------------------------------
'KH'

Happy Chinese New Year
Go to Top of Page

Billkamm
Posting Yak Master

124 Posts

Posted - 2006-01-25 : 16:30:39
If I used that method I would need to pass all of my parameters in with the sp_executesql statement and I have a lot of parameters and feel that would be a waste of resources if there is a way to evaulate the name of a paramter into its value.
Go to Top of Page

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2006-01-25 : 20:30:04
See this thread:

[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=60861[/url]
Go to Top of Page
   

- Advertisement -