Cross Apply --reducing the number of combinations

  • Hi,

    I have issue with ny cross apply.I'm currently using to combine values from 2 fields.

    example:

    fields A = 1,2,3

    fields B = X,Z

    using the cross apply give me that results :

    1,X

    1,Z

    2,X

    2,Z

    3,X

    3,Z

    But would like to keep only combinations with new components.Example :

    1,X

    1,Z

    2,Null

    3,Null,

    Thanks for your help

  • rhmohamed (3/13/2014)


    Hi,

    I have issue with ny cross apply.I'm currently using to combine values from 2 fields.

    example:

    fields A = 1,2,3

    fields B = X,Z

    using the cross apply give me that results :

    1,X

    1,Z

    2,X

    2,Z

    3,X

    3,Z

    But would like to keep only combinations with new components.Example :

    1,X

    1,Z

    2,Null

    3,Null,

    Thanks for your help

    So, when would 2 and 3 EVER have any "new components" that weren't already present in 1?

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

  • Hi,

    That's totally correct.

    was almost there by adding a distinct to my query and adding the PK.but seems not totaly correct.

    Best regards

  • rhmohamed (3/14/2014)


    Hi,

    That's totally correct.

    was almost there by adding a distinct to my query and adding the PK.but seems not totaly correct.

    Best regards

    What makes 2 and 3 different from 1?

    How do you identify "new components"?

    There's insufficient information to offer any useful answer.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

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

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