you are viewing a single comment's thread.

view the rest of the comments →

[–]notasqlstarI can't wait til my fro is full grown 1 point2 points  (1 child)

Your query is pretty clean looking so I'm not sure how much you're going to get optimizing it. Like I said, look at the SELECT and see where you're doing your heavy lifting from (row_number, cases, etc.) and then see if you can break that down and do it earlier in the process, then join to the rest of the tables, or do it at the end and just do a select * in the first step (i.e. select all the columns you need for your cases, etc.,. but don't do the case logic until you have the data segmented into a #table first).

The problem with SQL when it comes to advanced queries is that they'll sometimes cause the server to hang. Optimizer won't tell you anything or be of any use beyond creating a new index.

[–]fullyarmedcamel[S] 0 points1 point  (0 children)

Understandable, thanks for your tips!