Breaking a SP into smaller modules

  • Jeff Moden (9/24/2008)


    Folks, please... go back and look at the original post... the queries are identical except for the IF and the WHERE... just move the IF to the WHERE and be done with it.

    Whenever someone posts generic code like in th original post I always assume they have over simplified so I try to provide an answer that will work in a more complex situation.

    Hey, if the logic can be moved to the where clause with CASE or some other method great, but if not then "child" procs are the only other way to do it.

  • Jeff Moden (9/24/2008)


    Hey MATT! Congrats on becoming a proud member of the over 5k crowd!

    Is it just me or is the air thinner up here????:D

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • There's air?

    --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)

  • Create a table with queries and conditions,

    Loop through the cursor and match the condition with the condition value from the table and get the query

    something like

    declare c cursor for

    SELECTcondition,[QUERY_NAME] from dbo.table

    open c

    fetch next from c into @condition , @QUERYNAME

    while @@fetch_status=0

    BEGIN

    if @yourcondition_in_code = condition

    begin

    select @QUERYNAME

    end

    FETCH NEXT

    END

  • Wait for it...

    🙂

    There is no "i" in team, but idiot has two.
  • Thanks for all the help Guys !! Will try to find out the best solution for my scenario...

  • Dave (9/25/2008)


    Wait for it...

    🙂

    Heh... too easy... not even going to bother. 😛 I just shake my head and wonder. :Whistling:

    --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 7 posts - 16 through 21 (of 21 total)

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