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 |
|
putsik
Starting Member
2 Posts |
Posted - 2004-06-08 : 04:47:38
|
| Hi,Is it possbile to create a dynamic script in SQL?Example,Declare @CustomerID nvarchar(2), @CustomerName nvarchar(12), @DynamicFieldName nvarchar(100)DECLARE Customer_cursor CursorFOR SELECT cUSTOMERiD,CUSTOMERnAME From Customeropen Customer_CursorFETCH NEXT FROM Customer_CursorINTO @CustomerID,@CustomerNameWHILE @@FETCH_STATUS = 0BEGIN SET @DynamicFieldName = '@' + 'CustomerID' PRINT @DynamicFieldName--I want to output not @CustomerID but the actual @CustomerID value FETCH NEXT FROM Customer_Cursor INTO @CustomerID,@CustomerNameENDclose Customer_Cursordeallocate customer_CursorTy |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2004-06-10 : 19:18:35
|
| Nope, can't do it like this. @CustomerID is a variable defined in your procedure, you cannot dynamically re-build that variable name and reference it.But surely this must be an oversimplification of what you're really trying to do, because otherwise you would just do PRINT @CustomerID, right?-----------------------------------------------------Words of Wisdom from AjarnMark, owner of Infoneering |
 |
|
|
|
|
|