Member Function Concept.

  • Hi All,

    I have a Stored Procedure where i need a block of code to be Execute repeatedly if condition satisfy.

    It is possible by using a outside function,

    But I wants the Concepts of Member Function present in OOPS.

    More Clear...

    Ex: ---

    Proc Tests

    {

    Fun1() {};

    Fun2() {};

    Begin

    If (@var = 1) Fun1();

    End

    Begin

    If (@var =2) Fun1();

    End

    Begin

    If (@var = 3) Fun2();

    End

    Begin

    If (@var = 4) Fun2();

    End

    }

    Please help me....

    How to do this?

    Cheer!

    Sandy

    --

  • More Clear to all,

    Here In Above Post,

    My Stored Procedure is calling one function almost 30 nos. of time

    after checking the condition.

    if also i am using the out side function its very slow performing,

    So I need the suggestion from you all,

    how can i make it faster...?

    Cheers!

    Sandy.

    --

  • Jeff,

    Can you Please Look into this topic?

    Cheers!

    Sandy.

    --

  • Hey Sandy,

    Can you simply use a WHILE loop?

    WHILE [SomeCondition = TRUE]

    BEGIN

    EXEC sp_proc

    [Change Condition]

    END

    Or do you need something more like:

    exec sp_who

    go 5

    Putting the number next to the GO statement will make something execution multiple times.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Sandy (1/17/2008)


    Jeff,

    Can you Please Look into this topic?

    Cheers!

    Sandy.

    Another obvious cheat, Sandy?

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

  • Hey Grant,

    Nope, Actually I don't want to call any other Store Procedure or function from out side to main procedure.

    I wants to define a small block of code in side the same procedure, which can be executed as per the condition ...

    Actually Grant, it is not possible by While loop, I have already checked it..and due to the number of calling external function my store procedure performance getting slow..so I need you help.

    Can you please clear this line..

    exec sp_who

    go 5

    Cheers!

    Sandy.

    --

  • I still don't understand the problem fully, so I'm not sure I can help.

    The second line is just a short cheat that's available with the "go" statement that makes it execute multiple times. So the code would have executed sp_who 5 times in a row.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • For the original problem given where certain parameters determine which function may be exercised and returned, a simple CASE statement would be in order whether it be for a RBAR Gui proc or a set based process.

    If the parameters are to drive different processes, the processes should be in individual procs and a "Master" proc with IF blocks and EXEC's should control the flow. These are particularlly useful for RBAR GUI code but also have their application in set based batch code.

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

  • Unless someone is trying to teach that god-awful four-letter instruction I will not repeat here.

    Why someone would ever bring that directive back in, and into SQL Server of all things is beyond me.

    Sorry - post-traumatic stress syndrome. I think I will go huddle over in the corner for a while.....

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

  • Guess I havn't had enough coffee yet, Matt... which 4-letter instruction? Exec?

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

  • The one VB programmers fear most.... I'll give you a hint... G_T_ where underscore is the same letter.

    you need a bigger bat for THAT one....

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

  • OOOOHHHHHHHH!!! THAT 4-letter word! You're correct... it's a mortal sin to even speak it! 😛

    I have a "special" oversize bat for that one... forgot all about it 'cause haven't had to use it on anyone for years. :w00t:

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

  • Oh man, don't they have to kick you off the boards for 8 months like Don Imus if you use language like that?

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • No, no... you have to eat the boards if you use that word 😛

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

  • I think we need the bat for the MS programmer that left that command in T-SQL. I mean - what were they thinking?

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

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

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