A table has 2 columns:
ColA int
ColB datetime
Input some data as
ColA ColB
1 2/2/2005 (month/day/year)
1 2/3/2005
1 2/10/2005
1 3/10/2005
2 3/1/2005
2 3/5/2005
2 4/1/2005
2 5/1/2005
Need to write a store procedure:
The procedure has an input argument
refTime as datatime
What it do is:
For each group of rows with the same ColA, remove the rows which ColB < refTime, except the one which is the nearest to the refTime.
For example,
if refTime==2/5/2005, the following rows will be removed:
ColA ColB
1 2/2/2005
if refTime==3/6/2005, the following rows will be removed:
ColA ColB
1 2/2/2005
1 2/3/2005
2 3/1/2005
ColA int
ColB datetime
Input some data as
ColA ColB
1 2/2/2005 (month/day/year)
1 2/3/2005
1 2/10/2005
1 3/10/2005
2 3/1/2005
2 3/5/2005
2 4/1/2005
2 5/1/2005
Need to write a store procedure:
The procedure has an input argument
refTime as datatime
What it do is:
For each group of rows with the same ColA, remove the rows which ColB < refTime, except the one which is the nearest to the refTime.
For example,
if refTime==2/5/2005, the following rows will be removed:
ColA ColB
1 2/2/2005
if refTime==3/6/2005, the following rows will be removed:
ColA ColB
1 2/2/2005
1 2/3/2005
2 3/1/2005