Swap Firstname lastname

  • I was joining two tables on PersonFullname column when found that one tables has PersonFullname as Roger, Sharon whereas the other has Sharon Roger

    How can I swap one and Join the tables.

  • sharonsql2013 (2/2/2015)


    I was joining two tables on PersonFullname column when found that one tables has PersonFullname as Roger, Sharon whereas the other has Sharon Roger

    How can I swap one and Join the tables.

    If a comma is present, split on the comma and re-concatenate the parts with the understanding that the query will not be SARGable. If you have a lot of data like this, you might want to add a persisted computed column to the "comma" table that does the switch so that queries can be SARGable.

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

  • Post deleted because I realized Jeff suggested the same thing (a COMPUTED PERSISTED column).


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

Viewing 3 posts - 1 through 2 (of 2 total)

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