[KLUG Members] Data transformation

Adam Tauno Williams adam at morrison-ind.com
Fri Sep 23 11:36:23 EDT 2005


> I am taking data from a SQL database that is long, below is an example.. 
> User_id Field_id Field_value
> 1        1         data1
> 1        2         data2
> 1        3         data3
> 1        4         data4
> 2        1         data1
> 2        2         data2
> 2        3         data3
> 2        4         data4
> What I need to do is export it but into a wide file so that it looks like
> the following
> 1, data1, data2, data3, data4
> 2, data1, data2, data3, data4
> This will be used for both Postgres databases and MS SQL databases.. my main
> question is.. Can this be done with a SQL query or will the data have to be
> exported Long and then run through a program/script to change it to the wide
> format? Everything I have tried from an SQL stand point has not worked.. but
> I am not strong with SQL queries right now. 

In PostgreSQL at least you can do this easily in SQL.
http://www.postgresql.org/docs/7.4/interactive/arrays.html

I'm certain M$-SQL offers something equivalent.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://www.kalamazoolinux.org/pipermail/members/attachments/20050923/3091e781/attachment.bin


More information about the Members mailing list