r/SQLServer • • Jan 11 '23

Crying Screams in SQL.....

One wrong line of code in a Stored Proc has just cost me three days of debugging time...
I want to cry...

26 Upvotes

22 comments sorted by

3

u/Lurking_all_the_time Jan 12 '23

Just to clarify, I'm 20 years in the business and still amazed that SQL can kick me in the nuts like this.
The issue was with a report that was aggregating data in several ways from a history table. (First time this happened, last time this happened etc.) There were several aggregates and one of them was grouped wrongly. Very easy to miss when reading through the code, it was only when I started outputting each section and comparing it to what I expected that I finally clicked on what was wrong.

2

u/realzequel Jan 12 '23

If I had a dime for every complex SQL statement I had to deconstruct...

23

u/FoCo_SQL Enterprise Data Architect Jan 11 '23

Why did the DBA quit their job? They were tired of the denormalized working conditions.

Jokes aside, I feel your pain and you have my empathies.

4

u/stedun 2 Jan 12 '23

DROP it off, you’re KILLing me.

12

u/BCCMNV Jan 11 '23

It’s a rite of passage

11

u/mikeblas Jan 11 '23

Why didn't you find it sooner? (Seriously: this is a learning opportunity.)

7

u/WillLiftForBeer Jan 12 '23

Welcome to the profession of software development! New here? For real though, If you are new, this is a totally normal thing that happens to everyone - even when you’ve been doing it a long time. But, that’s what makes you a better developer - the more you’ve seen and been exposed to, the wiser you are. Bet you won’t make this same mistake again twice!

5

u/andrewsmd87 Jan 12 '23

You can't just leave us hanging what was it, and with detail!?

5

u/miabbqking Jan 12 '23

Pray tell!

5

u/Select-Distinct Jan 12 '23

One of the best ways I have found, is to ask someone to watch as you walk through the code

It doesnt even matter if they understand SQL to a high level, what this does is make you explain each step in simple terms to them, what almost always happens is that you spot the error whilst you are explaining the steps

5

u/slashd Jan 12 '23

rubber duck programming 👍

🦆🦆🦆

4

u/umair01 Jan 12 '23

I think we've all been there. Rite of passage for all fellow coders.

4

u/jib_reddit Jan 12 '23

I once had an other developer leave a USE Otherdatabase command in the middle of a large stored procedure, that one took some figuring out as to why it was doing half the changes and then just apparently not doing the other half.

2

u/civil_beast Jan 12 '23

Probably not a good time to ask about the DbMaint policy governing backups… ?

2

u/MasterClown Jan 12 '23

SELECT NOISE FROM LAMENTATIONS WHERE ANGST_LEVEL > 10

2

u/vasagle_gleblu Jan 12 '23

Yeah, that sounds about right...

2

u/solitary_learner Jan 12 '23

Hope it is NOT "DELETE FROM ..."

2

u/MidnightMoney9782 Jan 12 '23

I totally know what you mean…

We recently had a small change which was noticed after 6 months and totally destroyed a bunch of slowly changing dimension.

Analysis to find the error: about 1 week

Programming Time for a script to rebuild the dimensions: about 1 weeks

Script runtime: about 25 hours

Only because one of our programmers just wanted to change something quickly.

2

u/AtmospherePast4018 Jan 12 '23

Enter into Chat GPT and ask it to correct for syntax errors. Won’t work all the time but I’m finding it to be an excellent starting point for challenges like this.

0

u/[deleted] Jan 11 '23

[deleted]

4

u/Lurking_all_the_time Jan 11 '23

I think I'll get a McFlurry - there is a McDs not too far from me!

12

u/minormisgnomer Jan 12 '23

You may have to do debug the ice cream machine as wel

7

u/alinroc 4 Jan 11 '23

Keep emergency ice cream in your freezer at home. Cheaper and you can have any flavor and toppings you want.