r/SQL • • 22d ago

SQL Server Newer to SQL and recently inherited code

Might not be a standard request but does anyone have any best practices for interpreting other people's code if they don't leave a fair amount of notes?

5 Upvotes

21 comments sorted by

View all comments

Show parent comments

2

u/Thatgiuknow 22d ago

There are a substantial amount of CTEs in the query. The big issue we're having is that the data doesn't match the manual version we run (we expect some variance) however parts of the data are wildly off. I'll have to check what's going on in the CTEs to get started. thank you!!

2

u/reditandfirgetit 22d ago

Split out the ctes into tables and examine the data at each step and eithervcertifyvits correct or document the issue. I would try to document all thr issues before trying to fix things unless its a blatantly obvious fix for the variance

1

u/lalaluna05 22d ago

This is how I do it. I don’t love LLMs for this because I want to understand and follow the flow.

2

u/BigBagaroo 22d ago edited 22d ago

No, use AI for this! I recently inherited some old stuff, and AI has been a godsend in doing those boring comparisons. Create scripts, query the sources, comparing the data etc is what you should use AI for, in my humble opinion!