- 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
it hurts. please make it stop.
Admin
Admin
Please do! I am really quite proud of it!
Admin
IME, the REAL WTF is that some pointy-haired boss will look upon this code's creator as a genius coder, protect him politically in the organization and appoint him as mentor to any junior SQL developers coming into the department.
Admin
Isn't that kind of like keeping the blind, deformed, runt pup from the litter for breeding stock?
Admin
Completely agree. But I once had to write something similar to parse names into their parts to PUT them in different fields in the database. But what do you do with names like Billy Bob Thorton and Eddie Van Halen which no system can handle. Or international names where the family name comes first.
Admin
And to answer your question, only the abomination that starts SELECT * is one statement: every SELECT statement before the last one is a separate SQL statement within what is probably a stored procedure of some sort.
So THAT one thing is okay.
As for the the rest, like the content of the initial bunch of SELECTs … >S I G H<.
Admin
More to the point, Parsed Strings are a better idea in SQL. If the application parses the strings before storing them in the columns, then SQL can index them.
Databases exist to query and calculate results from data, not process that data.
Admin
This looks less like it was scripted and more like the 'ol "fill down" in Excel, then run through a SQL formatter.
Maybe the person who came up with that had nobler intentions... "With enough UNIONs, I can bring about world peace."
CAPTCHA: consequat = fruit that makes you wish you "hadn't"
Admin
Yes... but we are talking about someone who didn't know better than to store all three part of the name in seperate fields, dispite virtually every website on the internet seperating them on the presentation layer.
So... WTF : There was a much better way to output parts of a column as seperate columns... WTF : The columns should have been seperated to begin with WTF : Since we are retrieving the data as is... and leaving intact the present structure of the table, the application would have been the ideal place to seperate them.
I guess this is 3 WTFs for the price of one.
CAPTCHA: nulla... ummm... a good name for an explicitly declared global constant who'se value is null? HEY! THAT MAKES 4WTFs ... does it count?
Admin
THIS is why medical systems are so slow. That combined with the udder disaster that is the MUMPS programming language.
Admin
Sure... but just so long as they continue to use string valued primary keys, they should be okay.
Admin
This guy is an obvious user of that "little blue pill". That code has to be the result of blurred vision and a 4-hour hard-on.
CAPTCHA: "praesent" -- that's what he left the maintenance programmers...
Admin
Sounds like someone has a case of the Getting-Paid-By-The-Line-Of-Code-Days.
Admin
Actually, the semi-colon has been accepted in SQL Server since at least SQL 2005. In fact, a semi-colon is actually required in some cases (such as after a MERGE statement or immediately prior to a CTE declaration).
Admin
I'd say "WTF??!?!!!" but alas, I've seen some of these monster SQL statement too...
...my deepest sympathies, I truly feel for you
Admin
Does it work ?
Admin
Wow I need new eyes after reading that. He clearly shold have used a cursor and a variety of regexes to improve readability.
Admin
Ouch! Even if you didn't know about BETWEEN you would at least google to see if something like that exists instead of writing this monstrosity.
Admin
I can't decide whether this reminds me more of Philip Glass or Andy Kaufman.
Admin
If you think SQLCLR is the solution for this, you probably shouldn't be writing this function either.
Admin
As a double-named person I was going "please no" at "attempts to split a name like 'HARTLEY JR' into two parts."
Then I saw the code.
Admin
Eh, the new go forward for all new SQL commands introduced in SQL Server is that the new commands require terminator characters. It's ASNI SQL compliant.
From MSDN: ";" Transact-SQL statement terminator.Although the semicolon is not required for most statements in this version of SQL Server, it will be required in a future version.
Admin
I don't see the problem, some people really might have a 50 letter surname, especially if it's hyphenated or (as in some traditions) multiple names....
Admin
This is a proud step forward in SQL evolution. Soon we will have 3D games coded in SQL.
Admin
Assuming everyone's name follows the same form is generally a bad idea. Although I don't think anyone has actually come up with a decent solution.
A page I am fond of: http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/
In other news, fuck Akismet.
Admin
What's a "fryolator", DDBA?
Admin
Admin
Admin
Admin
Or search engines:
http://www.youtube.com/watch?v=Es9-l1up3r8
Admin
Admin
Admin
This is auto generated code. I used to own the auto that generated it. The auto's generator was so worn out, even the replacement generator was worn out. That auto was the real WTF.
Admin
My Linux PC has it though.
Admin
The fact that he didn't just use a few substring and replace functions to do this is just appalling. I would not be able to live with myself if this was something I wrote...
Admin
Admin
So we come to the quote: When you come to the fork in the road TAKE IT
Admin
I'm torn between saying "this is amazing" or "this is fake". I can't tell which, but it's definitely either of the two.
Though I do wonder how much better this was because of the lack of code snippets. Scrolling through it completely just feels more wtf-ish than "[snipped 10.000 lines]".
I'd say good job, keep it in there fully from now on, Alex! Though I did have to switch of "full text" mode.
Admin
"code snippets"... I meant: "removed code". "snipped code"? Ahh, whatever it's called.
Admin
Not even one teensy little bitty thing!
SQL annoys me because it pretends to offer stuff you could use to do this, but it provides neither the condition nor the scope that would actually allow you to do it. In theory, for example, you should be able to to use LOCATE() to do this, but you wind up with this monstrosity (to get last name from a "LAST, FIRST" field):
So, to split a field into last name and first name, I have to reference the same LOCATE a total of 4 times. And if I were to need to split one of the result fields again; well, I shudder even to think. If I have nested query tables, like in DB2, it can be made to work, but it is so clumsy.
To pretend that this is programming is to pretend that torture is a sunny day at the beach.
Addendum (2012-08-01 22:50): I decided this needed more clarification.
To make SQL look like it is programmable, the designers of the "language" emulate functions from other languages. The LOCATE function, for example, is a take-off from POS in Basic; and SUBSTR, likewise.
Unfortunately, SQL is not BASIC, and these functions are not suitable for use in a set language. So they don't fit the scope of the SQL language, because its scope is much more restrictive than the scope of a true programming language.
Even if they insisted on emulating such functions exactly, things would be made better if they bothered to anticipate the conditions you are likely to encounter when processing data, and allowed the functions to be more tolerant of those conditions. They won't do that either.
The result is that string processing in SQL is often an exercise in pure pain, unless of the data in that column conforms exactly to a specification. In this case, for example, the above can be greatly simplified if I can guarantee that every row contains a ', '. But, of course, no one wants to be bothered to keep data to a specification, including database designers.
There are a lot of things that could be done to ease this, if only they thought of SQL as a language in its own right, and stopped emulating everything else in its most restrictive form. As an example of this, suppose that there were two changes to the functions: (1) LOCATE returns null if the target string is not found; and (2) SUBSTRING accepts parameters outside the bounds of the string at the "edges". Then, a last-name first-name split of this type could be written:
Now, gee, wouldn't that be an improvement?
Even better would be if they actually thought about the problems that query designers are likely to face, so that if we had CSV data in a column, we could do something like this:
And then of course, we have:
(SPLIT parameters: 1-input column; 2-desired segment; 3-delimiter between the segments; 4-text qualifier as in CSV.)
And wouldn't that be easy?
So it would be so much better if they thought about the scope within which SQL expressions must operate and the conditions likely to be encountered in the data.
Addendum (2012-08-01 22:55): And, by the way, another annoying thing.
In DB2, I can cast a character string to a number:
...and so, of course, they provide no/nada/zilch/zip means to determine if the string is numeric beforehand.
So if I run this on a table column and hit a row that contains "XYZZY" in that column; well, too bad, dies.
It would be much better if there were an express function like CONVERT_INTEGER() that simply returned NULL if the text was not a valid number. But who would think of anything like that?
Admin
Admin
Admin
To a mere mortal, this seems like a WTF. However, to an SQL "guru"...
trails off into thoughts of the space-time continuum
Admin
This is mixing cake batter by pouring the mix, water and eggs into the bowl, then scooping it out into 165 separate portions into 165 tupperware containers, shuffling them around the counter, and then pushing them back into the bowl.
Admin
You're not the only ones who don't get this, that's why the SQL standard allows any number of procedural languages to be embedded to work around your deficient design.
SQL is a (roughly) relational language. If you're manipulating strings in it, you're Doing It Wrong. See this paper ($$ but worth it) and the first few chapters of CJ Date's Introduction to Database Systems.
But the bottom line is if you have "Mr. Smith" in your database and need access to "Mr." or "Smith", you should have split them into fields before they came into the database. The beauty of the relational schema is that, when properly normalized, all the informational complexity is clearly laid out: your database is exactly as complex as that schema looks. If you remove stuff or cheat to make it pretty, you are deluding yourself. If you do stupid tricks like entity attribute value, you have only hidden the complexity, but it's still there and will simply migrate to your app, usually in the form of a buggy rewrite of DBMS functionality.
Admin
Admin
Wow how efficient is that
Admin
The use of 'JR Hartley' as an example name indicates the submitter is at least mid-thirties and grew up in UK.
Admin
You don't need extra-special permissions to create temp tables in MSSQL (tested it with vanilla sql authentication account).
Also: which is worse? Creating temp tables or creating actual tables (and dropping them later) which needs more rights?
Also: I was being ironic. Nothing can possibly excuse a script like this!