Query how to?

  • I have to code a query to return a result set containing only the MemID's that are in the 2 org from the table structure and chart below... I think this needs to be done with a Stored procedure but not exactly sure how to do it.. anyone have an idea? Think of this as values for an org chart.

    MemID

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    ParID

    0

    1

    1

    1

    2

    2

    6

    6

    7

    4

    4

    1

    |-------|--------|

    2------ 3------- 4

    |----------------|

    5------6 10------11

    |----|

    7----8

    |

    9

    So - in this tree example the output should be: (because they all fall within the 2 MemId org...)

    MemId

    -------

    2

    5

    6

    7

    8

    9

  • Please provide your table definitions, and what queries you have tried so far.

    This will be more helpful and more consumable by the community trying to help you.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • CirquedeSQLeil (4/5/2010)


    Please provide your table definitions, and what queries you have tried so far.

    This will be more helpful and more consumable by the community trying to help you.

    I agree with Jason... we need some data and we need to know what the table(s) look like. Now, don't just run off and try to do that without reading the article at the first link in my signature line below.

    --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 3 posts - 1 through 2 (of 2 total)

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