Re: writing a query
From: Joe Celko (jcelko212_at_earthlink.net)
Date: 10/21/04
- Next message: Dena E: "Query Optimization Help"
- Previous message: Kyle Kaitan: "Newbie question: Using sp_tables to retrieve table names"
- In reply to: Rick: "writing a query"
- Next in thread: Rick: "Re: writing a query"
- Reply: Rick: "Re: writing a query"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 21 Oct 2004 16:53:26 -0700
>> What I need to do is total up some hours worked by a persons bill
rate. But, I need to be able to select the rate at the time the work is
performed. <<
Read the note at the cottomof this posting. In general the bst way to
handle these problems is with a history table that has durations:
CREATE TABLE BillRates
(ssn CHAR(9) NOT NULL,
start_date DATETIME NOT NULL,
end_date DATETIME, -- null is current
rate DECIMAL (12,4) NOT NULL,
PRIMARY KEY (ssn, start_date));
use a Calendar table and a BETWEEN predicate to fnd the rate for a date.
If you try to do this with just one date in the history, you get these
god-awful self-joins that are expensive to execute and bitch to
maintain.
And please learn the differences between fields and columns, or you'll
never understand SQL.
--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. Sample data is also a good idea, along with clear
specifications.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
- Next message: Dena E: "Query Optimization Help"
- Previous message: Kyle Kaitan: "Newbie question: Using sp_tables to retrieve table names"
- In reply to: Rick: "writing a query"
- Next in thread: Rick: "Re: writing a query"
- Reply: Rick: "Re: writing a query"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|