Sorry if this is a dumb question.
I need to run a query that returns the two records with the earliest date for each reference number. Also, I need to return a numeric value of 1 or 2 to indicate the position.
For example, if my data was:
REF DATE
111 1/1/2005
111 2/2/2005
111 3/3/2005
222 7/7/2006
222 8/8/2006
222 9/9/2006
333 4/4/2007
Then the query should return:
REF DATE ORDINAL
111 1/1/2005 1
111 2/2/2005 2
222 7/7/2006 1
222 8/8/2006 2
333 4/4/2007 1
I should add that this has to be achievable in plain SQL, as I am using the query as the source for a Crystal Reports Command statement.
Thanks in advance.
I need to run a query that returns the two records with the earliest date for each reference number. Also, I need to return a numeric value of 1 or 2 to indicate the position.
For example, if my data was:
REF DATE
111 1/1/2005
111 2/2/2005
111 3/3/2005
222 7/7/2006
222 8/8/2006
222 9/9/2006
333 4/4/2007
Then the query should return:
REF DATE ORDINAL
111 1/1/2005 1
111 2/2/2005 2
222 7/7/2006 1
222 8/8/2006 2
333 4/4/2007 1
I should add that this has to be achievable in plain SQL, as I am using the query as the source for a Crystal Reports Command statement.
Thanks in advance.