all groups > sql server (microsoft) > october 2007 >
You're in the

sql server (microsoft)

group:

Changing a field name into a column -- help normalizing


Changing a field name into a column -- help normalizing andydlove NO[at]SPAM gmail.com
10/25/2007 6:01:53 PM
sql server (microsoft):
Hi guys and gals,

I need help with a table I have. It looks something like this:

Log | Var1 | Var2 | Var3 | .....| Var300
-----------------------------------------------------
1 | Data
2 | Data
3 | Data

I want to rework the table so it reads:

Log | Var | Data
-----------------------
1 | Var1 | Data
1 | Var2 | Data
1 | Var3 | Data

and so on....

The reason I'm doing this is because I have a lot of data about the
Variables (Var1, Var2, Var3....) in a seperate table and I want to
link them together.

Thanks for your help,

Andy
Re: Changing a field name into a column -- help normalizing andydlove NO[at]SPAM gmail.com
10/25/2007 7:55:18 PM
[quoted text, click to view]
I meant Changing a field name into a row... sorry.

[quoted text, click to view]

Re: Changing a field name into a column -- help normalizing Ed Murphy
10/25/2007 8:32:32 PM
[quoted text, click to view]

See http://en.wikipedia.org/wiki/Entity-Attribute-Value_model
(particularly the "Downsides" section) for general background.

That said:

insert into new_table (Log, Var, Data)
select Log, 'Var1', Var1 from old_table
union
select Log, 'Var2', Var2 from old_table
union
AddThis Social Bookmark Button