• Jacob Wilkins (2/12/2016)


    Luis Cazares (2/12/2016)


    Jacob Wilkins (2/12/2016)


    No need to use window functions. A simple CROSS APPLY will do the trick.

    SELECT [OrderNumber]=OrderID,

    [User]=x.[User]

    FROM dbo.Orders CROSS APPLY (SELECT [User]=EnteredBy

    UNION ALL

    SELECT [User]=PerformedBy

    ) x([User])

    Cheers!

    Or the short version available since 2008.

    SELECT [OrderNumber]=OrderID,

    [User]=x.[User]

    FROM dbo.Orders

    CROSS APPLY (VALUES( EnteredBy),

    (PerformedBy)) x([User]);

    Heh, good point. Went on autopilot using the old stuff; one day I won't have to worry about 2005...one day. 🙂

    I know it's just me but I like the "old stuff". It's just as fast as the new stuff, as well. Guess it's a matter of what you cut your teeth on.

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