Import .CSV file into a table

  • Hello - new to SQL. I have a csv file (but when I open it up it looks more like an excel file but with csv extension) and would like to know how to best import the data into a table. Below is additional informations:

    1. I've already tried Import/Export wizard and it is giving me an erro something regarding data type error. I fixed but still not working.

    2. Only the first file has the column names and rest of the files that I may get just have data.

    3. I will be doing this in a daily basis

    4. After I import the data,would like to archive the file into archive folder.

    5. Would like to run the import at 11:00 PM each evening.

    Thanking you much.

  • Take a look at BOL (Books on line – the help file that comes with SQL Server) at Bulk insert statement. It seems that this is just what you need. You can import a CSV file into a table. You can specify the field separator (in your case a coma) or create a format file and specify everything in the format file (I would first try without format file). You can also specify at which line to begin. With your first file you can specify the second line, so you will not import the columns’ names. After you create the Bulk Insert command you can use it in a job.

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Thank you. I tried the Bulk Insert method and it did not work for me. Let me search BOL and try other methods and get back here for additional help.

  • Can you upload a small version of the text file (that will contain just few records) and a script for creating the table? Also if you'll post more details about your problem (your code, the error message that you received, etc') then there is a good chance that one of the readers will be able to help you.

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

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

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