How to import CSV file in SQL server 2008?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite
1












I am trying to import a CSV file in SQL Server 2008. BULK INSERT is a way to go but it is applicable for CSV from SQL Server 2014 onwards.



What would be an alternative way to achieve this goal?



Any thoughts/ideas much appreciated.










share|improve this question









New contributor




T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1




    Actually FORMAT='CSV' is 2017+ (14 is the major version number).
    – Aaron Bertrand♦
    58 mins ago
















up vote
2
down vote

favorite
1












I am trying to import a CSV file in SQL Server 2008. BULK INSERT is a way to go but it is applicable for CSV from SQL Server 2014 onwards.



What would be an alternative way to achieve this goal?



Any thoughts/ideas much appreciated.










share|improve this question









New contributor




T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1




    Actually FORMAT='CSV' is 2017+ (14 is the major version number).
    – Aaron Bertrand♦
    58 mins ago












up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





I am trying to import a CSV file in SQL Server 2008. BULK INSERT is a way to go but it is applicable for CSV from SQL Server 2014 onwards.



What would be an alternative way to achieve this goal?



Any thoughts/ideas much appreciated.










share|improve this question









New contributor




T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am trying to import a CSV file in SQL Server 2008. BULK INSERT is a way to go but it is applicable for CSV from SQL Server 2014 onwards.



What would be an alternative way to achieve this goal?



Any thoughts/ideas much appreciated.







sql-server sql-server-2008 import csv






share|improve this question









New contributor




T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 1 hour ago









LowlyDBA

6,62452241




6,62452241






New contributor




T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









T.H.

333




333




New contributor




T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 1




    Actually FORMAT='CSV' is 2017+ (14 is the major version number).
    – Aaron Bertrand♦
    58 mins ago












  • 1




    Actually FORMAT='CSV' is 2017+ (14 is the major version number).
    – Aaron Bertrand♦
    58 mins ago







1




1




Actually FORMAT='CSV' is 2017+ (14 is the major version number).
– Aaron Bertrand♦
58 mins ago




Actually FORMAT='CSV' is 2017+ (14 is the major version number).
– Aaron Bertrand♦
58 mins ago










1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










SQL Server has always supported bulk inserting from CSV files, you just have to specify field/row terminators.



file.csv contains:



foo,bar,1
blat,splunge,2


Then we do this:



CREATE TABLE #foo(a varchar(32), b varchar(32), c int);

BULK INSERT #foo FROM 'c:tempfile.csv'
WITH (ROWTERMINATOR = 'n', FIELDTERMINATOR = ',');

SELECT * FROM #foo;


Results:



a b c
-------- -------- ----
foo bar 1
blat splunge 2





share|improve this answer




















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "182"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    T.H. is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f221817%2fhow-to-import-csv-file-in-sql-server-2008%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote



    accepted










    SQL Server has always supported bulk inserting from CSV files, you just have to specify field/row terminators.



    file.csv contains:



    foo,bar,1
    blat,splunge,2


    Then we do this:



    CREATE TABLE #foo(a varchar(32), b varchar(32), c int);

    BULK INSERT #foo FROM 'c:tempfile.csv'
    WITH (ROWTERMINATOR = 'n', FIELDTERMINATOR = ',');

    SELECT * FROM #foo;


    Results:



    a b c
    -------- -------- ----
    foo bar 1
    blat splunge 2





    share|improve this answer
























      up vote
      4
      down vote



      accepted










      SQL Server has always supported bulk inserting from CSV files, you just have to specify field/row terminators.



      file.csv contains:



      foo,bar,1
      blat,splunge,2


      Then we do this:



      CREATE TABLE #foo(a varchar(32), b varchar(32), c int);

      BULK INSERT #foo FROM 'c:tempfile.csv'
      WITH (ROWTERMINATOR = 'n', FIELDTERMINATOR = ',');

      SELECT * FROM #foo;


      Results:



      a b c
      -------- -------- ----
      foo bar 1
      blat splunge 2





      share|improve this answer






















        up vote
        4
        down vote



        accepted







        up vote
        4
        down vote



        accepted






        SQL Server has always supported bulk inserting from CSV files, you just have to specify field/row terminators.



        file.csv contains:



        foo,bar,1
        blat,splunge,2


        Then we do this:



        CREATE TABLE #foo(a varchar(32), b varchar(32), c int);

        BULK INSERT #foo FROM 'c:tempfile.csv'
        WITH (ROWTERMINATOR = 'n', FIELDTERMINATOR = ',');

        SELECT * FROM #foo;


        Results:



        a b c
        -------- -------- ----
        foo bar 1
        blat splunge 2





        share|improve this answer












        SQL Server has always supported bulk inserting from CSV files, you just have to specify field/row terminators.



        file.csv contains:



        foo,bar,1
        blat,splunge,2


        Then we do this:



        CREATE TABLE #foo(a varchar(32), b varchar(32), c int);

        BULK INSERT #foo FROM 'c:tempfile.csv'
        WITH (ROWTERMINATOR = 'n', FIELDTERMINATOR = ',');

        SELECT * FROM #foo;


        Results:



        a b c
        -------- -------- ----
        foo bar 1
        blat splunge 2






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        Aaron Bertrand♦

        147k18279475




        147k18279475




















            T.H. is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            T.H. is a new contributor. Be nice, and check out our Code of Conduct.












            T.H. is a new contributor. Be nice, and check out our Code of Conduct.











            T.H. is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f221817%2fhow-to-import-csv-file-in-sql-server-2008%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            Installing NextGIS Connect into QGIS 3?

            One-line joke