The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

My ugly SQL by stoft2007-04-26 05:53:45
  Rewriting it helps quite a lot by sazzer 2007-04-26 06:54:42
SELECT 
    my_date + (
        CASE 
            WHEN 
                my_date BETWEEN 
                    next_day(to_date( extract(YEAR FROM my_date)||'0324','YYYYMMDD'), 'Sunday') 
                AND 
                    next_day(to_date( extract(YEAR FROM my_date)||'1024','YYYYMMDD'), 'Sunday')
            THEN 
                2 
            ELSE 
                1 
        END
    )/24 
FROM 
    my_table;
Looking at that, the next step I'd suggest is to either factor the entire CASE or just the next_day parts of it out into a function that is called, rather than leaving it all inline like that. Factoring out the CASE would leave you with something like
SELECT 
    my_date + (find_dst_offset(my_date))/24 
FROM 
    my_table;
[ Reply ]

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)