Re: converting single record with date range into multiple records
From: Joe Celko (jcelko212_at_earthlink.net)
Date: 06/30/04
- Next message: F HS: "Re: SQL query help (return only alphanumeric records)"
- Previous message: Jack D. Ripper: "Re: Sorry. I have an SP that accepts a WHERE clause as a parameter. Doesn't work ...kinda"
- Maybe in reply to: Steve H: "Re: converting single record with date range into multiple records"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 30 Jun 2004 12:52:25 -0700
Build a table for the buckets, or use an existing Calendar table:
CREATE TABLE MonthBuckets
(bucket_start DATETIME NOT NULL PRIMARY KEY,
bucket_end DATETIME NOT NULL);
Assuming that the start and end dates are always the first and last days
of a month:
CREATE VIEW MonthParts (part_nbr, startdate, enddate)
AS
SELECT P1.part_nbr, B1.bucket_start, B1.bucket_end
FROM Parts AS P1, MonthBuckets AS B1
WHERE P1.startdate BETWEEN B1.bucket_start AND B1.bucket_end
AND P1.enddate BETWEEN B1.bucket_start AND B1.bucket_end;
I would stick with a VIEW, which will update itself rather than carry
redundant information in the Database. If you are not familiar with
using a Calendar table, just Google the newsgroup and look at some old
postings. Unlike temporal functions, this is portable.
--CELKO--
===========================
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
- Next message: F HS: "Re: SQL query help (return only alphanumeric records)"
- Previous message: Jack D. Ripper: "Re: Sorry. I have an SP that accepts a WHERE clause as a parameter. Doesn't work ...kinda"
- Maybe in reply to: Steve H: "Re: converting single record with date range into multiple records"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|