I am trying to find the most efficient way to pivot the first two values for every "group by" in a recordset. For example, here is my table:
I need to group by Account and Form, and pivot the first two results together in the same row, as follows:
Notice that Account 1, Form B only has one record, therefore the second columns are null. Also notice that the third Form A record does not even come in. I had thoughts of using a "Top 2" combined with FIRST and LAST to pivot, but I ran into problems. Any thoughts? Thanks!
Code:
Account Form Date Score
1 A 1/8/07 89%
1 B 2/7/07 95%
1 A 8/3/07 72%
1 A 12/1/07 87%
2 C 3/1/07 98%
2 C 10/16/07 95%
I need to group by Account and Form, and pivot the first two results together in the same row, as follows:
Code:
Account Form Date1 Score1 Date2 Score2
1 A 1/8/07 89% 8/3/07 72%
1 B 2/7/07 95%
2 C 3/1/07 98% 10/16/07 95%
Notice that Account 1, Form B only has one record, therefore the second columns are null. Also notice that the third Form A record does not even come in. I had thoughts of using a "Top 2" combined with FIRST and LAST to pivot, but I ran into problems. Any thoughts? Thanks!