I've got a table (TYPE, DAYMTH) where it is a compound key and the
DAYMTH is a datetime but all years are 1900 ONLY THE day and month are
significant.
What I want to do is for each type, find the next n dates - so for
example:
TYPE DAYMTH
1 1900-02-20
1 1900-05-05
1 1900-09-14
1 1900-11-11
2 1900-03-03
2 1900-07-07
if I want to get the next 3 dates after 22 June 2005 it should give me:
1 2005-09-14
1 2005-11-11
1 2006-02-20
2 2005-07-07
2 2006-03-03
2 2006-07-07
so, anyone got any bright ideas?
I've started down this route:
create table #year (yr int)
insert into #year values(2005)
insert into #year values(2006)
insert into #year values(2007)
insert into #year values(2008)
select *,convert(datetime,convert(varchar,yr) +
substring(convert(varchar,daymth,20),5,20),20)
from DAYMTHtable,#year
where convert(datetime,convert(varchar,yr) +
substring(convert(varchar,daymth,20),5,20),20) > getdate()
order by type,convert(datetime,convert(varchar,yr) +
substring(convert(varchar,daymth,20),5,20),20)
and although this seems to be a good start I wonder if there are better
solutions. Also any quick ideas on how to finish if I decide to follow
my existing thought process?
thanks
Phil