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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Get the mailserver that powers this list at 
http://www.houseoffusion.com/banners/view.cfm?bannerid=17

Message: http://www.houseoffusion.com/lists.cfm/link=i:6:2062
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=89.70.6
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to