The only way to know for sure is to write it both ways and benchmark them.
There are too many variations of hardware, database design, etc. to make
a blanket statement.
_____________________
Eric
_____________________
"I used to think that the brain was the most wonderful organ in my body.
Then I realized who was telling me this."
-- Emo Phillips
"Peterson, Chris" <[EMAIL PROTECTED]>
10/20/2004 11:28 AM
Please respond to sql
To: "SQL" <[EMAIL PROTECTED]>
cc:
Subject: Best SQL query method
Question on Optimization in SQL:
What do you think would be faster, a CASE statement for all 50 states to
group them into regions, or inner joining to a file that has the regions
setup and each state defined?
With CASE, I would not have to have the 5th file joined to this query, and
as the origin state field is non-indexed, I think the inner join would
hamper the query pretty badly.
Anyone have any 'best practice' advice?
Here is my current query....
SELECT
SUM(CASE
WHEN F2.ORBAMT > 0 THEN F2.ORBAMT
ELSE ((SELECT
SUM(DISMNF)
FROM
LOAD
WHERE
LOAD.DIODR## = F2.ORODR##) * 1.35)
END) as Revenue,
MONTH(SUBSTR(DIGITS(0+F1.DIDATE),2,7)) as Month,
YEAR(SUBSTR(DIGITS(0+F1.DIDATE),2,7)) as Year,
F4.NMAREG as Region,
SUM(F1.DISMNF) as LoadedMiles,
SUM(F1.DIEMIL) as EmptyMiles,
COUNT(F2.ORODR##) as OrderCount
FROM
LOADDATE F1 INNER JOIN ORDBILL F2 ON F1.DIODR## =
F2.ORODR##
INNER JOIN ORDER F3 ON F1.DIODR## = F3.ORODR##
INNER JOIN NMSAREA F4 ON Trim(F3.OROST) = Trim(F4.NMACOD)
WHERE
F1.DIDATE >= 2004001
AND F1.DIDATE <= 2004274
AND F1.DIDISP = '01'
AND ORSTAT IN ('D', 'E')
GROUP BY
YEAR(SUBSTR(DIGITS(0+F1.DIDATE),2,7)),
MONTH(SUBSTR(DIGITS(0+F1.DIDATE),2,7)), F4.NMAREG
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Purchase from House of Fusion, a Macromedia Authorized Affiliate and support the CF
community.
http://www.houseoffusion.com/banners/view.cfm?bannerid=37
Message: http://www.houseoffusion.com/lists.cfm/link=i:6:2064
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/6
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:6
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.6
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54