- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The two branches are not identical btw. They differ also in the where mur=, ref=
Admin
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.
Admin
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.
Admin
The most simple variant I could come up with, while keeping it sane and readable:
Admin
What are you all complaining about? At least, the database is not an Excel file.
Admin
They who fail to understand SQL are condemned to be repeatedly on TDWTF.
Admin
Does that mean TDWTF is a SQ-Hell? :D
Admin
You broke it! SELECT @ref = ref should be OUTSIDE the if statement, or in both the BEGIN and ELSE...
Admin
Actually, I missed something ... that looks much nicer, by eliminating another SELECT that's not needed some of the time
Admin
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.
Admin
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.
Admin
Actually this will usually perform worse than using 2 statements as the database has a hard time to distinct between the two different access paths.
Admin
A preview is a much requested item.
Admin
a) You may need an is not null on the first part
b) It is not clear how most databases would optimize such a query and they probably could not cache a plan well for such a query.