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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Accession Columns Names as an Array

Author  Topic 

hanglam
Starting Member

7 Posts

Posted - 2005-11-15 : 18:49:20
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 = 1


I tried this:

declare @index varchar(2)
set @index = '3' (column with the name '3')

UPDATE Table1 Set @index = 'hello' where PersonID = 1

but it doesn't work.



Thanks,
Hang

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-11-15 : 19:31:49
Have you thought about redesigning your table? You can do this with dynamic SQL; however, the design is questionable. It might be better to have a column indicating what day of the month it is. Have you explored dynamic SQL at all?

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-11-15 : 19:32:47
Please do not cross post:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57804

And yes, two different people are telling you this is a poor design (now three).
Go to Top of Page
   

- Advertisement -