Comment On SQL Splits

"I should probably start by saying that I am not a SQL expert," Paul wrote. "Sure, I've written my share of SELECT statements, plenty of UPDATE statements, and even a few ALTER statements, but beyond that... nada." [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: SQL Splits

2012-08-01 10:02 • by Esse (unregistered)
If you are going to do it dirty, at least use a loop and create dynamic SQL statements.

Re: SQL Splits

2012-08-01 10:02 • by Kriis (unregistered)
Wow... just... wow

Re: SQL Splits

2012-08-01 10:03 • by Not a code monkey (unregistered)
You can do this in one line in Haskell

Re: SQL Splits

2012-08-01 10:04 • by Kriis (unregistered)
386070 in reply to 386067
Esse:
If you are going to do it dirty, at least use a loop and create dynamic SQL statements.


Loop? This saves the processing power required to do that. Talk about optimized. I want to learn from this guy.

Re: SQL Splits

2012-08-01 10:05 • by Tim (unregistered)
386071 in reply to 386068
Kriis:
Wow... just... wow

likewise

Re: SQL Splits

2012-08-01 10:09 • by Warren (unregistered)
If you even start writing this without thinking "there must be a better way", you're not a programmer, just a typist that knows SQL.

Re: SQL Splits

2012-08-01 10:11 • by Some Jerk (unregistered)
Ugggh!
Blah Blah Blah : Paid by the line
Blah Blah Blah : The real WTF is <Insert Ignorant Statement Here>

Yes... this is someone you should really learn from. If you can master this talented individuals' skills, you may even be able to work for Able's Car Wash writing a foxpro database to total daily inclome!

Re: SQL Splits

2012-08-01 10:12 • by Some Jerk (unregistered)
386074 in reply to 386072
Warren:
If you even start writing this without thinking "there must be a better way", you're not a programmer, just a typist that knows SQL.


Correction... a typist who happens to know a website that displays sql code.

Re: SQL Splits

2012-08-01 10:13 • by Ozzy (unregistered)
TLDR

captcha: minim (oh the irony)

Re: SQL Splits

2012-08-01 10:19 • by Andrew (unregistered)
At least he used temp tables.

Re: SQL Splits

2012-08-01 10:21 • by Sreejith K. (unregistered)
386077 in reply to 386072
Warren:
If you even start writing this without thinking "there must be a better way", you're not a programmer, just a typist that knows SQL.


I agree.

Re: SQL Splits

2012-08-01 10:21 • by John (unregistered)
386078 in reply to 386071
Tim:
Kriis:
Wow... just... wow

likewise


My reaction was "Oh god, please no", followed by "no, no, no, no..." as I continued to scroll down.

Re: SQL Splits

2012-08-01 10:22 • by Matyas (unregistered)
Somebody please shoot me now! Reading through this is causing me so much pain...

Re: SQL Splits

2012-08-01 10:25 • by PiisAWheeL
Who has time to write all this shit? PBTL?

Edit: On second look, I see no ;'s. Is that all 1 statement? Jesus.

Re: SQL Splits

2012-08-01 10:26 • by iToad (unregistered)
String processing with SQL. What could possibly go wrong?

Re: SQL Splits

2012-08-01 10:30 • by Gary (unregistered)
386082 in reply to 386069
Not a code monkey:
You can do this in one line in Haskell

You can do it in one line in a lot of languages. More to the point, you can probably do it in ~1 line of SQL, if you let that line get very long.

Breaking these up for readability:


select left(lname, case charindex(' ', lname) when 0 then len(lname) else charindex(' ',lname)-1 end) as part1,
right(lname, len(lname) - charindex(' ', lname)) as part2,
lname
from nametable


Limiting this to looking at the last four characters would be trivial.

Re: SQL Splits

2012-08-01 10:34 • by Chronomium (unregistered)
386083 in reply to 386081
iToad:
String processing with SQL. What could possibly go wrong?
Indeed, this is clearly one of those cases where you're using a screwdriver to mix cake batter.

Re: SQL Splits

2012-08-01 10:35 • by Zylon
386084 in reply to 386083
Chronomium:
iToad:
String processing with SQL. What could possibly go wrong?
Indeed, this is clearly one of those cases where you're using a screwdriver to mix cake batter.

This is mixing cake batter using another cake.

Re: SQL Splits

2012-08-01 10:40 • by russianyaz (unregistered)
Whaaat?!??!

Re: SQL Splits

2012-08-01 10:51 • by dguthurts (unregistered)
TRWTF is that first name, last name, and initials are not separate fields in the table.

Gawd. I wonder how this mess would handle Mr. John Smith, Jr. DDS?

Re: SQL Splits

2012-08-01 10:54 • by Valrandir (unregistered)
386088 in reply to 386081
This can't be real

Re: SQL Splits

2012-08-01 10:57 • by dkf
386089 in reply to 386084
Zylon:
This is mixing cake batter using another cake.
Looks a lot like it's being mixed with a whole bonus bakery.

Re: SQL Splits

2012-08-01 10:59 • by refoveo (unregistered)
My mouse scroll wheel just gave me a blister.

Re: SQL Splits

2012-08-01 11:03 • by Some Jerk (unregistered)
386091 in reply to 386090
refoveo:
My mouse scroll wheel just gave me a blister.


My Krapometer redlined

Re: SQL Splits

2012-08-01 11:07 • by Herwig (unregistered)
Just GREAT!

Re: SQL Splits

2012-08-01 11:10 • by QJo
This one is making my eyeballs bleed.

Re: SQL Splits

2012-08-01 11:11 • by Steve The Cynic
Hey, at least we now know what knives are for.

Stabbing idiots like this, that's what.

Re: SQL Splits

2012-08-01 11:24 • by ubersoldat
386095 in reply to 386067
I don't know why but this looks like auto-generated code, it has to be auto-generated code, only an algorithm can be this DUMB!

From this we can conclude that the surname table column is VARCHAR(54) right? Luckily it was VARCHAR(255).

Re: SQL Splits

2012-08-01 11:26 • by Disguntled DBA (unregistered)
Some of the lesser sins that would merely have his code bounced in code review:

1) Ordering on insert into a temp table (WHY??)
2) Casting join columns (Way to use indexes, dumbass)

In this case, however, I think the correct course of action is job retraining. Preferably something involving paper hats, a fryolator, and a requirement that he wear a badge that reads "TRAINEE" for the first year.

Re: SQL Splits

2012-08-01 11:36 • by Andrew (unregistered)
Other people, when confronted with a problem like this think "Gee, I'll use regex!"

Oh look, a problem sanely solved.

Re: SQL Splits

2012-08-01 11:38 • by galgorah
String Parsing is really not a good idea in SQL. Its a performance killer. This looks like something that would be better suited in the application code. If a lot of string parsing has to be done in sql, its a candidate for SQLCLR.

That being said. There is a much better way to do this...

Re: SQL Splits

2012-08-01 11:38 • by Pablo Lerner (unregistered)
386100 in reply to 386081
I think just the string processing

Re: SQL Splits

2012-08-01 11:40 • by But (unregistered)
386101 in reply to 386076
Andrew:
At least he used temp tables.

That could actually make it worse. If this is SQL Server (which it looks like) then temporary tables are created in tempdb, which means that the script will fail if the account running it doesn't have Create Table permissions in tempdb.

Re: SQL Splits

2012-08-01 11:41 • by Grzechooo (unregistered)
Hmm, I ain't a SQL expert, but dealing with strings is something on app side, not on SQL side, am I right?

Re: SQL Splits

2012-08-01 11:44 • by Some Jerk (unregistered)
386103 in reply to 386102
Depends on the circumstances. There are better ways to do it on the SQL end as well. Under the circumstances however, given that it only transforms the output, it would definately be better to do this on the app end.

Re: SQL Splits

2012-08-01 11:52 • by dc (unregistered)
386104 in reply to 386072
Warren:
If you even start writing this without thinking "there must be a better way", you're not a programmer, just a typist that knows SQL.


But on the plus side, they passed their typing final with flying colors! 666 words per second?

Re: SQL Splits

2012-08-01 11:53 • by YR (unregistered)
I could claim this is bullshit and the sender faked it... but I doubt he'd go into the trouble of creating this, so what I can say is...

... take this expert, and tie him. And bury him. Waist below into an ant's nest. Under a hornet's nest. And kick the hornets. Please.

Re: SQL Splits

2012-08-01 11:56 • by Demon (unregistered)
386106 in reply to 386081
This isn't a query, it's a war declaration!

Re: SQL Splits

2012-08-01 12:01 • by Some Jerk (unregistered)
386108 in reply to 386106
Demon:
This isn't a query, it's a war declaration!


It is what happens when you attempt to create Artificial Intelligence from Authentic Stupidity.

Re: SQL Splits

2012-08-01 12:05 • by paquetted
One word: OMG!

Re: SQL Splits

2012-08-01 12:08 • by coward (unregistered)
386110 in reply to 386081
Exactly this

Re: SQL Splits

2012-08-01 12:08 • by ShatteredArm
What an idiot. He should've used table variables.

Re: SQL Splits

2012-08-01 12:09 • by persto (unregistered)
God forbid writing a function that splits strings by space characters (while maybe uniforming space characters first).

Re: SQL Splits

2012-08-01 12:11 • by TK (unregistered)
386114 in reply to 386068
Kriis:
Wow... just... wow


That's all I could say when I was looking at the code. This is an epic WTF

Re: SQL Splits

2012-08-01 12:20 • by Evan (unregistered)
386115 in reply to 386083
Chronomium:
iToad:
String processing with SQL. What could possibly go wrong?
Indeed, this is clearly one of those cases where you're using a screwdriver to mix cake batter.

I've used pliers to eat a pancake before.

(It was a camping trip and we had a shortage of silverware because we're stupid, but I had my Leatherman.)

Re: SQL Splits

2012-08-01 12:27 • by Wow... (unregistered)
386117 in reply to 386081
I'm no expert either, but I'm speechless...
By the way, cool name iToad...

Re: SQL Splits

2012-08-01 12:28 • by Ignatz (unregistered)
Any fule no you have to use XML for really enterprisey string manipulation in SQL.

SELECT XmlName.value('FirstName[1]', 'varchar(30)'),
XmlName.value('LastName[1]', 'varchar(30)')
FROM (
SELECT XmlName = CAST('<FirstName>' + REPLACE(clinician_name, ' ', '</FirstName><LastName>') + '</LastName>' AS XML)
FROM (
SELECT clinician_name = 'Bugs Bunny'
UNION ALL SELECT 'Fred Flintstone'
UNION ALL SELECT 'Barney Rubble'
) names
) split

Let values with anything other than exactly one space character be an exercise for the student.

Re: SQL Splits

2012-08-01 12:42 • by Not at all (unregistered)
Loop unrolling always gives you that critical performance boost.

Re: SQL Splits

2012-08-01 12:46 • by myName (unregistered)
The real WTF is posting all of it without any snipping.

Re: SQL Splits

2012-08-01 12:54 • by Keith (unregistered)
386121 in reply to 386083
This leads to a delicious vodka and orange infused cake.
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment