• Peter Sawatzki (unregistered)

    The two branches are not identical btw. They differ also in the where mur=, ref=

  • (nodebb)

    This article should be labelled "How to screw over your database by caching the worst execution plan or the day I decide to recompile my procedures every time".

  • (nodebb)

    We don't know what the consultant was paid to do, so the WTF can't be on his side until we know more. Seems to me he went in to point the finger to some sore spots, and by the looks of it, he found them (and filled his report with some mumbo jumbo to keep the PHB happy.) The feature that sends this to the frontpage of this site is the sheer incompentence by the company to figure out the problems by themselves.

  • Hal (unregistered)

    Granted we do not know if the procedure is inside a transaction itself, but I don't see any transactions in the procedure. This leads me to ask if querying the orders table for the same key multiple times and taking a different attribute from each query ever leads to integrity problems in the application.

  • (not a)[email protected](or is it) (unregistered)

    The most simple variant I could come up with, while keeping it sane and readable:

    IF @origin IN (-2, -4, -5, -6, -7, -8, -9)
    BEGIN
    	SELECT @id = sender_id
    			, @group = user_group
    			, @file_ref = file_ref 
    	FROM order 
    	WHERE ref = @mur
    	
    	SELECT @ref = ref 
    	FROM order 
    	WHERE mur = @mur
    END
    ELSE 
    	SELECT @id = sender_id
    			, @group = user_group
    			, @file_ref = file_ref
    			, @ref = ref  
    	FROM order 
    	WHERE mur = @mur
    
  • Sauron (unregistered)

    What are you all complaining about? At least, the database is not an Excel file.

  • (nodebb)

    They who fail to understand SQL are condemned to be repeatedly on TDWTF.

  • Sauron (unregistered) in reply to mynameishidden

    Does that mean TDWTF is a SQ-Hell? :D

  • (nodebb) in reply to Sauron

    Ah, the good old "Why are you complaining about murder when I didn't piss on the grave" argument. Never gets old :-)

  • DJ Dizzy Spudplucker (unregistered) in reply to (not a)[email protected](or is it)

    You broke it! SELECT @ref = ref should be OUTSIDE the if statement, or in both the BEGIN and ELSE...

  • DJ Dizzy Spudplucker (unregistered) in reply to (not a)[email protected](or is it)

    Actually, I missed something ... that looks much nicer, by eliminating another SELECT that's not needed some of the time

  • (nodebb)

    No ifs or buts, but there are some ands. (And handles @origin being null.)

    select @id = sender_id, @group = user_group, @file_ref = file_ref, @ref = ref from order where (@origin in (-2, -4, -5, -6, -7, -8, -9) and ref = @mur) or ((@origin is null or @origin not in (-2, -4, -5, -6, -7, -8, -9)) and mur = @mur)

    Addendum 2024-04-24 15:20: Apparently I need to learn what the formatting methods are for DailyWTF.

  • (nodebb)

    It's basically markdown but a very limited form of it (https://www.markdownguide.org/).

    The append comment feature mislabeled "Edit" is no help here either especially since the character limit includes those addendums. A "Preview" feature would be arguably more useful for a site that requires a lot of formatting due to the discussion topics often including source code and structural data.

  • Carsten (unregistered) in reply to RyanTG
    Comment held for moderation.
  • (nodebb) in reply to MaxiTB

    A preview is a much requested item.

  • David Williams (unregistered) in reply to RyanTG
    Comment held for moderation.

Leave a comment on “Query Query Query”

Log In or post as a guest

Replying to comment #:

« Return to Article