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
 SQL Server Development (2000)
 SQL data re-formatting

Author  Topic 

MaverickUK
Yak Posting Veteran

89 Posts

Posted - 2004-07-02 : 11:33:42

Hi guys

I've knocked up a quick questionnarie ASP database system.
After an ASP form is submitted it loops through each form object name and value submitted in the ASP page and saves it to the database.

So in the database I have a 3 column table holding the FormObjectName, FormObjectValue and FormID ( which is unqiue to each form submitted )

So in the table, data looks like

FormName, FormValue, FormID
Q1, 123, 1
Q2, ABC, 1
Q1, asdas, 2
Q2, 32432, 2
etc...

I want to run a procedure that'll return that data as this format

FormID, Q1, Q2
1, 123, asdas
2, ABC, 32432
etc...

I'm guessing this is some type of pivot procedure? But even if it is, I've never done it because.
Please could somebody share their experience in this area?
Thanks

drymchaser
Aged Yak Warrior

552 Posts

Posted - 2004-07-02 : 12:12:37
select FormID
, MAX(CASE WHEN FormName = 'Q1' THEN FormValue ELSE null END) 'Q1'
, MAX(CASE WHEN FormName = 'Q2' THEN FormValue ELSE null END) 'Q2'
...
from table
GROUP BY FormID

also do a search here for Dynamic CrossTab because it may come in handy here.
Go to Top of Page

MaverickUK
Yak Posting Veteran

89 Posts

Posted - 2004-07-05 : 04:37:12
Thx
Go to Top of Page
   

- Advertisement -