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 - 2003-03-06 : 07:28:27
|
| Clemens writes "I want to do the do the following:DECLARE @SQL VARCHAR(200)DECLARE @FiscalStr VARCHAR(10)DECLARE @counter INTSET @counter=1WHILE @counter<=4BEGINSET @SQL='SELECT @FiscalStr=FiscalYear' + CAST(@counter AS VARCHAR) + ' FROM EstimatesNotes WHERE CompanyID=15'EXEC (@SQL)PRINT @FiscalStr SET @counter=@counter+1ENDThe thing is, I need the different values from FiscalYear1..FiscalYear4. I have to use these values as a filter in another query. The code above does not work. I understand why, but how do I get these values?Thanks in advance." |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-03-06 : 08:19:07
|
| DECLARE @SQL NVARCHAR(200) DECLARE @FiscalStr VARCHAR(10) DECLARE @counter INT SET @counter=1 WHILE @counter<=4 BEGIN SET @SQL='SELECT @FiscalStr=FiscalYear' + CAST(@counter AS VARCHAR) + ' FROM EstimatesNotes WHERE CompanyID=15' EXEC sp_executesql @SQL, N'@FiscalStr VARCHAR(10) out', @VARCHAR(10) outPRINT @FiscalStr SET @counter=@counter+1 END ==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|