Import and Modify Data in SQL Server

Posted on 2011-10-03
Last Modified: 2012-05-12
I have a CSV file that I am trying to import into SQL Server 2008.  This file contains values that are all surrounded with quotation marks.  I want to remove the quotation marks from the data as I insert the data into the database; the reason being some of the fields are integers, and therefore cannot accept quotation marks.

Is there some way I can use a SQL function such as REPLACE() to remove the quotation marks from the data with SQL before it gets inserted?



Question by:nickgross19

    Author Comment

    If you could show me the full code to create a table and insert the data from a CSV File that would also be helpful.
    LVL 59

    Accepted Solution

    How have you tried to do the import? Are you using the Import and Export Wizard in SQL Management Studio. Additionally, are you going to a staging table first? If so, you can convert numbers after the fact as well as other tasks to ensure data is clean before moving to production table. Otherwise, you would set the data type during import. If this is a repeated import, there are other options, but figure I would start with the simplest.
    LVL 21

    Expert Comment

    by:Alpesh Patel
    if you are doing using SSIS then it will be possible using the Derived column. In that replace the quotation with blank.

    Author Closing Comment

    I think this solution is one way to do it; you can import the data into the table and modify it after you insert it.  This solution did not address how to remove values during the insertion process though.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
    There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 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

    23 Experts available now in Live!

    Get 1:1 Help Now