Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transposing rows

Status
Not open for further replies.

rafeman

Technical User
Oct 20, 2004
66
GB
This may or not be possible, but here we go;

I have a SQL table as such;

SchoolNo Notes Date
1000 Visited 01/09/06
1021 Not interested 10/06/06
1021 Now interested 11/06/06
1000 Spoke to teacher 10/07/06
1000 not interested 10/09/06

Is there a way we can convert the row to columns so each row is a schoolno with seperate columns for each row. Ideally it would need to be column1 - latest date to last column oldest date.

E.g.
SchoolNoNote1 Date1 Note2 Date2
1000 not interested 10/09/06 visited 01/09/06 and so on
1021 now interested 11/06/06 not interested 10/06/06

Is it possible?

Thanks
 
Hi,

If I get it right, you want to have your columns be expandable. I wouldn't go for such a solution since it is bad for performance and bad for maintainability.

Also not that there is a limit in the number of columns.

A better aproach would be to create multiple tables like this schema:

SCHOOL
ID int
NAME varchar

NOTES
ID int
SCHOOL_ID int
NOTE varchar

Eventually if the notes are always from a list, you can set them also in a dedicated table.

Greetz,

Geert



Geert Verhoeven
Consultant @ Ausy Belgium

My Personal Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top