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 2005 Forums
 Transact-SQL (2005)
 Field selecting dilema...!!

Author  Topic 

bendertez
Yak Posting Veteran

94 Posts

Posted - 2008-07-02 : 10:26:43
Hello

I have a field that holds a person's course record called COURSE in a table called PERSON.

People can be studying more than one course at a time so entries in the table can look like this (with PID being the person id and ref being the person's initials):

PID- REF- COURSE
123- DC-- Comm Skills
123- DC-- IT Skills
123- DC-- First Aid
123- DC-- Health&Safety
344- GD-- IT Skills
344- GD-- First Aid
225- SW-- Health&Safety

What I need to do is create a data extraction file to be imported in to another system but have to get the COURSE data out in to individual fields. i.e.
for the person (PID) 123 i need to take their course data and seperate it in to the 4 diferent courses and enter the values in to 4 seperate fields:

Field1------------Field2----------Field3---------Field4-------
Comm Skills------IT Skills---------First Aid------Health&Safety

Can this be achieved?

Thank you

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-02 : 10:43:18
use the PIVOT operator


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

bendertez
Yak Posting Veteran

94 Posts

Posted - 2008-07-02 : 10:52:33
quote:
Originally posted by khtan

use the PIVOT operator


KH
[spoiler]Time is always against us[/spoiler]






Does the PIVOT operator not work the other way around though?

Where it will get data in the format of my required output fields and turn then in to a structure something that I started with?

Can I reverse a pivot or specify a format?

Thanks
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-02 : 10:59:31
read the BOL http://msdn.microsoft.com/en-us/library/ms177410.aspx?wt.slv=RightRail


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -