SQL Query Structure Training

  • I’m wondering what I would need to focus and revise on if I want to improve my thinking process whilst creating a query or a stored procedure when I’m dealing with a fair amount of data. For example, I understand how to get data from various tables and using the correct join to represent data but what I’m having difficulty with is writing SQL when I have to manipulate the actual data. An example would be to get all customers who have made a complaint in the last month, now that’s easy, but getting the first occurrence of a customers complaint? The last? So instead of getting the data that actually exists I’m talking about the thought process of using the existing data to get the desired result. I’ve heard of CTE’s, I’ve heard of temp tables/sets etc. So what would be a recommended way to get a good grip on all this, and if somebody could point me to a suitable training tutorial I'd appreciate it. Thanks.

  • It's certainly not a panacea but there is a thought process that helped me immensely.  So much so that I added to my signature line below years ago.  That and the understand that, as sophisticated as it is, SQL Server is basically a file handler and things like a SELECT are basically a loop (cursor) that's executed at near machine language levels behind the scenes (I refer to such loops as a "Pseudo Cursor", which is the term for such things first coined by R. Barry Young on these very forums).

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply