stored procedures

I had to debug a problem with a third-party e-commerce system today at work. It took a while to isolate the problem, and when I did, it led me to a certain stored procedure, which turned out to be 7400 lines long. I don’t think I’d ever seen a single stored proc quite that big before. Is that normal? I figured out what it was doing by running SQL Profiler, with the “TSQL_SPs” template that shows all the statements being executed within the procedure. With all the if/then logic in the proc, it was really only executing about 1000 lines of SQL for any given run. Still, that’s a lot to comb through just to figure out why the logic was returning wholesale prices instead of retail.

I also found a number of lengthy queries in the proc that ended with “and 1=2”, which would of course prevent that query from returning any results. I’m wondering why someone would do that rather than comment out the query. It made it fairly difficult to find the queries that were actually executing and returning results.

Leave a Reply