Using Comments to Quickly Test CTEs

  • Comments posted to this topic are about the item Using Comments to Quickly Test CTEs

  • Neat trick!

    .

  • Nice, thanks for sharing. Although I must point out a flaw with your program's logic... 50 isn't old!

    Ben

    ^ Thats me!

    ----------------------------------------
    01010111011010000110000101110100 01100001 0110001101101111011011010111000001101100011001010111010001100101 01110100011010010110110101100101 011101110110000101110011011101000110010101110010
    ----------------------------------------

  • Nice tip, but as a person over 50 I can only give one star.

  • It would be nice if MS could add pre-compile directives similar to C++ or C# -

    #define, #if, #undefine, etc...

    Dan Beggs

  • i like this a lot 🙂

    Thanks for sharing.

  • Guess I'm a dinosaur at 57! Funny, I don't consider myself "old"! 😀

  • Hey! I'm 61 and nowhere close to done.

    This is nice thing to do when you are trying to understand some other persons code. Especially if it already has block comment as most of mine do.

    My technique is to test the first level of a CTE before adding the next level

    ATBCharles Kincaid

  • We may be old, but as long as we can learn new tricks, we're not too old. 🙂

  • This makes my decision to retire at 56 much easier 🙂

    Final.Answer!

  • Retire? Me? Never! They will find me dead at the keyboard!!

    First of September I just got out of six months in a medical facility. It did not cost me an arm and a leg. Just the leg :w00t:

    Beside software I write a bit of poetry.

    Yesterday Nothing

    Today Nothing

    Tomarrow Nothing

    Retirement?

    Or is this something else

    By a different name?

    ATBCharles Kincaid

  • I concure regarding the age bit 🙂

  • Charles Kincaid (11/10/2014)


    My technique is to test the first level of a CTE before adding the next level

    Ah now that's an approach that doesn't really work for me, if I stop to test a CTE I will forget what to write next by the time I'm done. If I'm writing something at all complex that requires multiple levels of CTEs I sit and stare at the screen for several minutes whilst I juggle data in my head. I eventually get this notion that my current thought process is 'right' and then have to quickly type the whole lot down before my thought process changes or I will have to start again. I can't afford to think about what I'm doing, I just have to dump whats in my head to the screen.

    Tricks like this for testing after it has been written as oposed to testing during the writing suit me well! Generally speaking I come up with my final solution first time but often need to tweak details like sort orders or including additional columns etc.

    Ben

    ^ Thats me!

    ----------------------------------------
    01010111011010000110000101110100 01100001 0110001101101111011011010111000001101100011001010111010001100101 01110100011010010110110101100101 011101110110000101110011011101000110010101110010
    ----------------------------------------

  • Ben. Whatever works for you. 😎

    ATBCharles Kincaid

  • My technique is to put all of those queries at the end. Then I can enable the test queries or the final result query as a block of text and only be concerned with having patched out the queries not to use. For instance to test the content of "OldPeople":

    WITH

    People AS (

    SELECT 1 ID, 'Joe' FirstName, 'Smith' LastName, 21 Age, 'Male' Gender UNION ALL

    SELECT 2 ID, 'John' FirstName, 'Smit' LastName, 32 Age, 'Male' Gender UNION ALL

    SELECT 3 ID, 'Jo' FirstName, 'Schmit' LastName, 43 Age, 'Female' Gender UNION ALL

    SELECT 4 ID, 'Joanne' FirstName, 'Smith' LastName, 54 Age, 'Female' Gender UNION ALL

    SELECT 5 ID, 'Juan' FirstName, 'Smithe' LastName, 65 Age, 'Male' Gender

    )

    ,

    OldPeople AS (

    SELECT * FROM People WHERE Age > 50

    )

    ,

    Men AS (

    SELECT * FROM People WHERE Gender = 'Male'

    )

    --select * from People

    select * from OldPeople

    --select * from Men

    --SELECT

    -- o.*

    --FROM

    -- Men AS m

    -- INNER JOIN OldPeople AS o

    -- ON m.ID = o.ID

Viewing 15 posts - 1 through 14 (of 14 total)

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