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 |
|
skillile
Posting Yak Master
208 Posts |
Posted - 2001-11-27 : 09:31:03
|
| I have a table with the columns:level1lablevel2lablev...to lev10labI want to execute a select like thisdeclare @offstep intdeclare @x nvarchar(15)declare @str varchar(500)SET @offstep=6SET @x=1while @x <= @offstepbegin set @str= ' level'+ @x+'lab' + ' from tblcorpprof' select @str SET @x= @x+1endI can't get it to execute the values just the text.Any help. Thnanksslow down to move faster... |
|
|
btrimpop
Posting Yak Master
214 Posts |
Posted - 2001-11-27 : 09:32:50
|
| Do it dynamically, something like this:set @str= 'Select level'+ @x+'lab' + ' from tblcorpprof'exec(@str)"In theory there is no difference between theory and practice. But in practice there is!" |
 |
|
|
skillile
Posting Yak Master
208 Posts |
Posted - 2001-11-27 : 09:35:29
|
| worked great. Thanks ;)slow down to move faster... |
 |
|
|
shankarc
Starting Member
37 Posts |
Posted - 2001-11-27 : 09:35:32
|
| Try executing the SQL statement using sp_executeSQL or Exec. Please refer to dynamic SQL in the SQLteam.com Articles. |
 |
|
|
|
|
|