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 - 2004-07-13 : 10:20:07
|
| Des writes "How can I dynamically set the fields i want to select in a stored procedure.For example if i had a table with field names 1,2 3 etc and i only wanted the value of the field 2 but did not know which field until execution time how would i do this?" |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-07-13 : 10:38:28
|
| Dynamic sql:declare @sql varchar(4000)declare @Columnname varchar(100)set @columnname = 'Column3'set @sql = 'SELECT ' + @columnname + ' FROM MyTable WHERE ' + @columnname + ' = 10 'exec(@sql)Duane. |
 |
|
|
|
|
|