SQL Server: Split a nvarchar(10) column with data into two nvarchar(5) columns

Posted on 2007-09-28
Last Modified: 2008-03-03
I imported a data set into SQL and it looks like I have incorrectly mapped a column, setting two nvarchar(5) columns as one nvarchar(10) column. This column already has data, how do I safely split the column in two?
Question by:coldchillin
    LVL 75

    Expert Comment

    by:Aneesh Retnakaran
    Any criteria to split the data ?
    LVL 1

    Author Comment

    In half. The data will look like this

    abcd abcd
    abc   abcde
    LVL 15

    Accepted Solution

    UPDATE myTable
    SET col2 = SUBSTRING(col, 6, 5)

    UPDATE myTable
    SET col = SUBSTRING(col, 1, 5)

    SELECT * FROM myTable

    If everything looks okay then:

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
    Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

    754 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

    22 Experts available now in Live!

    Get 1:1 Help Now