r/SQLServer • u/Lurking_all_the_time • 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...
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
12
11
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
5
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
4
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
2
2
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
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
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.
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.