473,385 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

set of dates

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

Jul 23 '05 #1
3 1271
Why not just populate your calendar table with all the years you'll ever
need instead of just one year? 200 years would be less than 1MB of data and
would make all your queries much simpler.

--
David Portas
SQL Server MVP
--
Jul 23 '05 #2
Here's a different attempt:

DECLARE @dt DATETIME
SET @dt = '20050622'

SELECT type,
DATEADD(YEAR,YEAR(@dt)-1900+
CASE WHEN MONTH(daymth)*100+DAY(daymth)
<MONTH(@dt)*100+DAY(@dt) THEN 1 ELSE 0
END,daymth) AS dt
FROM daymth
ORDER BY type, dt ;

--
David Portas
SQL Server MVP
--
Jul 23 '05 #3
this doesn't work as it will give me 4 dates for 1 and 2 dates for 2.

I decided to carry on with my initial thoughts and followed the first
select (which I changed to select into #tmp) with this:

select t.* from #tmp t where 3 > (select count(*) from #tmp t2
where t.type = t2.type and t2.fdate < t.fdate)
order by type
ALSO, although you're right about my year table it would require a
database change which as you probably know sometimes meets resistance
from DBAs/Project Managers etc and generally is a whole lot more hassle.

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Riley | last post by:
The date fields being saved by a VB program were being saved as #2003-11-22#. For reasons unknown to me these dates began to be saved as "11/22/2003" All of these dates were made dates with the...
7
by: Alistair | last post by:
diary_date = request.form("diary_date") - (from a populated drop down list) strSQL = "SELECT saz_title, saz_text from saz_details where saz_date =#" & diary_date & "#" a response.write...
5
by: PW | last post by:
<rant> Sorry guys, but I just have to whinge. Dates in ASP are a total pain in the butt! I seem to get caught out so many times. I realise its my own fault, but going from the posts in this...
10
by: Colin Steadman | last post by:
I'm a stupid ASP programmer and I dont do Javascript (except for very simple tasks anyway), and I'm in a bit of a predicament. I've used a javascript table sorting script from here: ...
1
by: Don Sealer | last post by:
I have a report that includes 5 different subreports. I'd like to be able to open this report using a date function (Start Date and End Date). I'd like all five subreports to show the data from...
2
by: Rachel Suddeth | last post by:
Is there a way to have the non-selectable dates (those before MinDate and after MaxDate) draw differently so my users can see right away what dates aren't allowed? I'm not seeing it... ...
12
by: Dixie | last post by:
I am trying to calculate the number of workdays between two dates with regards to holidays as well. I have used Arvin Meyer's code on the Access Web, but as I am in Australia and my date format is...
1
by: pitfour.ferguson | last post by:
My dbase has the start date and end date of each visit. How can I ask Access to list the day of the week of the start (easy), end (easy) and, more importantly, the dates of the visit itself - ie...
7
by: evilcowstare via AccessMonster.com | last post by:
Hi, I have searched the forum for answers on this and to be honest as a novice I find it a bit confusing so apologies if it is simple. There are some searches that I want to apply to my database....
2
by: Jim Carlock | last post by:
(1) Does PHP provide any way to handle dates prior to 1980? I know there's problems with Microsoft Windows NT and all Windows NT operating systems will allow a date prior to 1980 to be placed...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.