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 |
|
hanglam
Starting Member
7 Posts |
Posted - 2005-11-15 : 18:45:18
|
| Hi,I have a table with the following columns:Table1:PersonID, [1], [2], [3],][4] , [5] and so on .The TABLE FIELD NAMES are actual numbers (not letters) representing the days of a month.I'mm writing a stored procedure to populate this table with UPDATE Statement (NOT INSERT statements as the PersonID is already in the table)is there any way for me to access the column as a array ?For example:UPDATE Table1 Set column[4] = 'hello' where PersonID = 1I tried this:declare @index varchar(2)set @index = '3' (column with the name '3')UPDATE Table1 Set @index = 'hello' where PersonID = 1but it doesn't work.Thanks,Hang |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-11-15 : 19:12:04
|
| No.Bad design.declare @sql varchar(1000)declare @index varchar(2)set @index = '3' (column with the name '3')select @sql = 'UPDATE Table1 Set [' + @index + '] = 'hello' where PersonID = 1'exec (@sql)yuk!==========================================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. |
 |
|
|
|
|
|