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.
Author |
Topic |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2001-11-27 : 08:51:47
|
Isaac Olson writes "How do I execute a sql statement that I have concatenated together as a string within a user-defined function? When I try to use exec('[my sql statement]') I am given an 'Invalid use of exec within a function' error. If this is not possible, then alternatively, is there a way to reference a column in a table by using a variable? Such as:declare @myColumn nvarchar(255)set @myColumn = 'LastName'select * from Users where @myColumn = 'Flintstone'Anything anywhere close will be greatly appreciated...pulling hair out at this point!" |
|
ToddV
Posting Yak Master
218 Posts |
Posted - 2001-11-27 : 13:06:40
|
Post the details of what you are trying to accomplish and maybe we can help. One possibility is something like this:select * from Users where Col1 = CASE WHEN @myColumn = 'Col1' THEN 'Flintstone' ELSE Col1 ENDAND Col2 = CASE WHEN @myColumn = 'Col2' THEN 'Flintstone' ELSE Col2 END |
|
|
|
|
|