How do I populate a specific column based on other columns in the same table?

Posted on 2009-05-01
Last Modified: 2012-05-06
I am trying to populate a column with concated values from other columns in the same table.  This 'new column' is blank and needs to be filled like so:

1  |   2  |  3  |  4  | new colum
a  |  b  |  c  |  d  |       abcd
e  |  f  |  g  |  h  |        efgh

and so on.  Can I construct a query that will fill every row of 'new column' with the values from the other 4 columns?
Question by:edgecrusher762
    LVL 92

    Accepted Solution

    UPDATE SomeTable
    SET NewColumn = COALESCE([1], '') + COALESCE([2], '') + COALESCE([3], '') + COALESCE([4], '')

    Author Closing Comment

    Thanks a ton.  Works perfectly.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Viewers will learn how the fundamental information of how to create a table.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now