I have looked through many examples on the web for PIVOT commands, but am still struggling to find the right way of doing it. Its probably somehitng really simple that i am missing, but if you could help me that would be great
I am creating a database to handle ranking points for Badminton, and have created a table with the following structure:
create table tempstore(
tmp_agegrp varchar(5), -- age group of the players U12 / U14 etc
tmp_event varchar(5), -- event type MS, WS, MD, WD, XD
tmp_event_id numeric (3,0), -- Event code (numeric which is a FK to the events table)
tmp_playerno numeric (5,0), -- Unique player number (numeric which is a FK to the players table)
tmp_points numeric (5,0) -- ranking points obtained in that event.
the format that has been requested by my provincial body is:
Age_group Event Player_number Event1 Event2 Total
U12 MS 1 100 100 200
All the examples i have seen online tend to have one field as the key on the left side, where as here i have 3 (age, event, playernumber) and this is where i am having problems as i cant seem to find the right syntax in the TSQL to merge these together.
As i said, might be something stupidly simple that i am missing, but its gone midnight now and brain is shutting down!
If anyone has done anything similar and would like to share their code your help would be very much appreciated before i resort to manual extracts and EXCEL VLOOKUPS!
Thanks in advance.