I have the following SQL
SELECT CNumber, MAX(FormSubmitted), Score
FROM dbo.vw_MSA
WHERE (Score IS NOT NULL)
GROUP BY CNumber, Score
Results:
CNumber FormSubmitted Score
0011509 2010-09-13 10:22:46.763 11
0016239 2010-09-28 13:53:58.557 8*
0016239 2010-10-12 11:52:33.150 12
0018792 2010-11-02 13:17:37.437 3
0051089 2010-10-07 11:38:29.257 13
0051091 2010-10-01 12:01:30.450 0
0067987 2010-09-29 11:06:48.490 7
0079351 2010-09-30 09:49:10.747 34
0833933 2010-09-30 12:54:19.013 6
0848185 2010-10-07 12:08:42.087 6
5010590 2010-11-01 09:54:14.790 6*
5010590 2010-11-16 15:23:50.350 12
I’m sure I should be able to sort this easily but for whatever reason I’m struggling atm. I need Score included in the results but having this in the GROUP BY inevitably returns more than just the record with the latest FormSubmitted date. Can anyone help me out in updating this query so I will get the Score in the results but only those records that are the maximum FormSubmitted date i.e exclude those marked *?
1 Answer