Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SELECT x AS 'y'
Message
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Miscellaneous
Thread ID:
01379000
Message ID:
01379008
Views:
19
If you need to set parameter to be equal to the field's value, then it's another story.

select @myParameter = FieldName, @myOtherParameter = myOtherFieldName from ....

>>I bet Sergey can figure out a way to do this!
>>
>>If I have the following SQL statement, it works fine:
>>
>>SELECT CodesKey AS 'codesdeptkey', * from codes
>>
>>I'd like to parameterize this, but if I try this it gives an incorrect syntax error:
>>
>>DECLARE @KeyName varchar(50)
>>SET @KeyName = 'codesdeptkey'
>>SELECT CodesKey AS @KeyName, * from codes
>>
>>Any ideas??? (other than obvious setting a string to the whole SELECT string and then EXECing that ... the SELECT string is obviously more complicated than what I've indicated above).
>>
>>TIA,
>>~~Bonnie
>
>Looks like you need dynamic SQL. There is no other way to make the name of the field dynamic, at least I don't know any.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform