LIghter fare - Doh! Querys

  • Heh... they even made the same mistake that caused the y2k crisis...

    Best T-Shirt I ever saw on the subject of "SQL Darwin Awards" was...

    [font="Courier New"] SELECT *

    FROM Users

    WHERE Clue > 0

    (0 row(s) affected)[/font]

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I have that shirt, you can buy it at thinkgeek.com. 😉

  • Jeff Moden (12/13/2007)


    Heh... they even made the same mistake that caused the y2k crisis...

    Best T-Shirt I ever saw on the subject of "SQL Darwin Awards" was...

    [font="Courier New"] SELECT *

    FROM Users

    WHERE Clue > 0

    (0 row(s) affected)[/font]

    I've seen a few other cutes ones at CafePress, although I haven't had the guts to buy any for the team (they're just on the other side of acceptable).

    Delete

    From Office

    where Intelligence='ID10T'

    select UserID, sum(complaints) as annoyances

    from users

    where

    IQ=0 and

    skills=0 and

    Nickname like '%dumbass%'

    group by Loudness

    having sum(complaints)>1

    or

    I swear to use the Key, the whole key and nothing but the primary key, so help me Codd

    or (cute)

    "My daddy's a database professional;

    My mommy is his data model.

    (I'm the resultset)"

    I could go on...hehe. Check them out for a giggle.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Too Funny!

    sqldumbass.com is getting hit when I get home tonight.

    I also have the SQL Shirt from thinkgeek.com. I tend to wear it to disaster recovery sessions (the drills, not the real thing) or on a long

    weekend day for a major database upgrades.

    "Key"
    MCITP: DBA, MCSE, MCTS: SQL 2005, OCP

  • A good source of WTF examples is thedailyWTF.com, and this is one of my all-time favorite T-SQL examples.

    [Code]ALTER TRIGGER [tgIntegrity_InsertUpdateCampaignNumber] ON [customer_products]

    FOR INSERT, UPDATE

    AS

    DECLARE @customer_number VARCHAR(20)

    DECLARE @campaign_number VARCHAR(20)

    DECLARE campaigncheck_cur CURSOR

    FOR SELECT [action].campaign_number

    FROM [action]

    INNER JOIN inserted

    ON [action].person_customer_number = inserted.customer_number

    AND [action].campaign_number = inserted.campaign_number

    WHERE [action].action_number = [action].root_action_number

    OPEN campaigncheck_cur

    FETCH NEXT FROM campaigncheck_cur INTO @campaign_number

    IF NOT @@fetch_status = 0

    BEGIN

    RAISERROR ( 'The campaign attached does not match any campaign attached to a root action for this person customer.', 16, 1 )

    ROLLBACK TRANSACTION

    END

    CLOSE campaigncheck_cur

    DEALLOCATE campaigncheck_cur[/Code]

  • Scott Coleman (1/21/2008)


    A good source of WTF examples is thedailyWTF.com, and this is one of my all-time favorite T-SQL examples.

    I think I just threw up in my mouth a little bit...

  • I just had to fix a database that had 14 tables (out of 60 total tables) with identity columns, but no primary key or clustered index defined. Another table had the clustered index on a varchar column, but the primary key was an identity column. Another table had five different indexes that were just on the LastName column.

    Same database had two many-to-many tables that had unique indexes on one of the two join columns. Another many-to-many table had no primary key, no indexes, and several instances of over 1,000 duplicate rows. They couldn't quite figure out why reports running on queries that used that table were returning such amazingly incorrect aggregates.

    I won't even go into the recursive cursors that call other recursive cursors. (Yes, multi-level, multi-step recursion.)

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 7 posts - 16 through 21 (of 21 total)

You must be logged in to reply to this topic. Login to reply