IS there a CSV Quotechar function as in Python suitable for Bulk Insert into MS SQL Server?












0















CSV reading and writing with quotechar '|' in Python



The csv format below allows to read and write files via Python with columns that contain the specified delimiter (',' in this case). In this case, the ',' is placed between the B values of the second entry.



AAAAA, |B,BB|, CCC



The following Python code can be used for, e.g. writing lines to the file:



    with open(self.base_uri + filename, 'w') as f:
writer = csv.writer(f,
delimiter=',',
quotechar='|',
quoting=csv.QUOTE_MINIMAL)

for row in data_list:
writer.writerow(row)




Difficulties wiht Bulk Insert into MS SQL Server



When trying to use the csv.file to apply a bulk insert in MS SQL Server, an error occurs for each line, where a quotechar is included:



take a look here



The SQL code I have utilized so far looks like this:



bulk insert DATABASE
from 'C:UsersXXDocumentssample.csv'
with
(
rowterminator='n',
fieldterminator=','
)


Do you have any ideas on how to fix this issue?
Is there any equvalent to the quotechar in Python in MS SQL Server?





Some questions about the topic :
Bulk insert with text qualifier in SQL Server










share|improve this question



























    0















    CSV reading and writing with quotechar '|' in Python



    The csv format below allows to read and write files via Python with columns that contain the specified delimiter (',' in this case). In this case, the ',' is placed between the B values of the second entry.



    AAAAA, |B,BB|, CCC



    The following Python code can be used for, e.g. writing lines to the file:



        with open(self.base_uri + filename, 'w') as f:
    writer = csv.writer(f,
    delimiter=',',
    quotechar='|',
    quoting=csv.QUOTE_MINIMAL)

    for row in data_list:
    writer.writerow(row)




    Difficulties wiht Bulk Insert into MS SQL Server



    When trying to use the csv.file to apply a bulk insert in MS SQL Server, an error occurs for each line, where a quotechar is included:



    take a look here



    The SQL code I have utilized so far looks like this:



    bulk insert DATABASE
    from 'C:UsersXXDocumentssample.csv'
    with
    (
    rowterminator='n',
    fieldterminator=','
    )


    Do you have any ideas on how to fix this issue?
    Is there any equvalent to the quotechar in Python in MS SQL Server?





    Some questions about the topic :
    Bulk insert with text qualifier in SQL Server










    share|improve this question

























      0












      0








      0








      CSV reading and writing with quotechar '|' in Python



      The csv format below allows to read and write files via Python with columns that contain the specified delimiter (',' in this case). In this case, the ',' is placed between the B values of the second entry.



      AAAAA, |B,BB|, CCC



      The following Python code can be used for, e.g. writing lines to the file:



          with open(self.base_uri + filename, 'w') as f:
      writer = csv.writer(f,
      delimiter=',',
      quotechar='|',
      quoting=csv.QUOTE_MINIMAL)

      for row in data_list:
      writer.writerow(row)




      Difficulties wiht Bulk Insert into MS SQL Server



      When trying to use the csv.file to apply a bulk insert in MS SQL Server, an error occurs for each line, where a quotechar is included:



      take a look here



      The SQL code I have utilized so far looks like this:



      bulk insert DATABASE
      from 'C:UsersXXDocumentssample.csv'
      with
      (
      rowterminator='n',
      fieldterminator=','
      )


      Do you have any ideas on how to fix this issue?
      Is there any equvalent to the quotechar in Python in MS SQL Server?





      Some questions about the topic :
      Bulk insert with text qualifier in SQL Server










      share|improve this question














      CSV reading and writing with quotechar '|' in Python



      The csv format below allows to read and write files via Python with columns that contain the specified delimiter (',' in this case). In this case, the ',' is placed between the B values of the second entry.



      AAAAA, |B,BB|, CCC



      The following Python code can be used for, e.g. writing lines to the file:



          with open(self.base_uri + filename, 'w') as f:
      writer = csv.writer(f,
      delimiter=',',
      quotechar='|',
      quoting=csv.QUOTE_MINIMAL)

      for row in data_list:
      writer.writerow(row)




      Difficulties wiht Bulk Insert into MS SQL Server



      When trying to use the csv.file to apply a bulk insert in MS SQL Server, an error occurs for each line, where a quotechar is included:



      take a look here



      The SQL code I have utilized so far looks like this:



      bulk insert DATABASE
      from 'C:UsersXXDocumentssample.csv'
      with
      (
      rowterminator='n',
      fieldterminator=','
      )


      Do you have any ideas on how to fix this issue?
      Is there any equvalent to the quotechar in Python in MS SQL Server?





      Some questions about the topic :
      Bulk insert with text qualifier in SQL Server







      python sql-server csv pymssql






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 30 '18 at 17:13









      M. StraubeM. Straube

      11




      11
























          3 Answers
          3






          active

          oldest

          votes


















          0














          I guess you need FIELDQUOTE:




          Specifies a character that will be used as the quote character in the CSV file. If not specified, the quote character (") will be used as the quote character as defined in the RFC 4180 standard.




          bulk insert DATABASE
          from 'C:UsersXXDocumentssample.csv'
          with
          (
          rowterminator='n',
          fieldterminator=',',
          fieldquote = '|'
          )


          If you are using version lower than 2017, you could genereate your CSV with quotechar equals " indstead of pipe symbol.






          share|improve this answer
























          • Thank you for the fast reply! I am using MS SQL Management version 2014. Fieldquote is therefore not an option. I have changed the utilized quotechar, just as you stated, from pipe symbol ( | ) to double quotes ( " ). Data entries now look like this: AA, "BBB,BB", CC Nonetheless. I receive the same errors when trying to start the bulk insert as before.

            – M. Straube
            Dec 30 '18 at 17:46





















          0














          You can try a format file: If you have applied quotes on your 2nd column...
          [csvfile] contains AAAAA,"B,BB",CCC



          Create Table csvfile
          (
          f1 VarChar(10),
          f2 VarChar(10),
          f3 VarChar(10)
          )

          BULK INSERT csvfile
          FROM 'c:downloadssample.csv'
          WITH (FORMATFILE = 'c:downloadssample.fmt');


          sample.fmt



          14.0
          3
          1 SQLCHAR 0 10 ","" 1 f1 SQL_Latin1_General_CP1_CI_AS
          2 SQLCHAR 0 10 ""," 2 f2 SQL_Latin1_General_CP1_CI_AS
          3 SQLCHAR 0 10 "rn" 3 f3 SQL_Latin1_General_CP1_CI_AS





          share|improve this answer

































            0














            Based on the answer of @Lukasz Skoda, I was able to find another solution.
            I have set the delimiter to pipe ( | ) and the quotechar to ( " ). Thanks to everyone trying to help me!






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              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',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              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
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979742%2fis-there-a-csv-quotechar-function-as-in-python-suitable-for-bulk-insert-into-ms%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              I guess you need FIELDQUOTE:




              Specifies a character that will be used as the quote character in the CSV file. If not specified, the quote character (") will be used as the quote character as defined in the RFC 4180 standard.




              bulk insert DATABASE
              from 'C:UsersXXDocumentssample.csv'
              with
              (
              rowterminator='n',
              fieldterminator=',',
              fieldquote = '|'
              )


              If you are using version lower than 2017, you could genereate your CSV with quotechar equals " indstead of pipe symbol.






              share|improve this answer
























              • Thank you for the fast reply! I am using MS SQL Management version 2014. Fieldquote is therefore not an option. I have changed the utilized quotechar, just as you stated, from pipe symbol ( | ) to double quotes ( " ). Data entries now look like this: AA, "BBB,BB", CC Nonetheless. I receive the same errors when trying to start the bulk insert as before.

                – M. Straube
                Dec 30 '18 at 17:46


















              0














              I guess you need FIELDQUOTE:




              Specifies a character that will be used as the quote character in the CSV file. If not specified, the quote character (") will be used as the quote character as defined in the RFC 4180 standard.




              bulk insert DATABASE
              from 'C:UsersXXDocumentssample.csv'
              with
              (
              rowterminator='n',
              fieldterminator=',',
              fieldquote = '|'
              )


              If you are using version lower than 2017, you could genereate your CSV with quotechar equals " indstead of pipe symbol.






              share|improve this answer
























              • Thank you for the fast reply! I am using MS SQL Management version 2014. Fieldquote is therefore not an option. I have changed the utilized quotechar, just as you stated, from pipe symbol ( | ) to double quotes ( " ). Data entries now look like this: AA, "BBB,BB", CC Nonetheless. I receive the same errors when trying to start the bulk insert as before.

                – M. Straube
                Dec 30 '18 at 17:46
















              0












              0








              0







              I guess you need FIELDQUOTE:




              Specifies a character that will be used as the quote character in the CSV file. If not specified, the quote character (") will be used as the quote character as defined in the RFC 4180 standard.




              bulk insert DATABASE
              from 'C:UsersXXDocumentssample.csv'
              with
              (
              rowterminator='n',
              fieldterminator=',',
              fieldquote = '|'
              )


              If you are using version lower than 2017, you could genereate your CSV with quotechar equals " indstead of pipe symbol.






              share|improve this answer













              I guess you need FIELDQUOTE:




              Specifies a character that will be used as the quote character in the CSV file. If not specified, the quote character (") will be used as the quote character as defined in the RFC 4180 standard.




              bulk insert DATABASE
              from 'C:UsersXXDocumentssample.csv'
              with
              (
              rowterminator='n',
              fieldterminator=',',
              fieldquote = '|'
              )


              If you are using version lower than 2017, you could genereate your CSV with quotechar equals " indstead of pipe symbol.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Dec 30 '18 at 17:26









              Lukasz SzozdaLukasz Szozda

              80.2k1066105




              80.2k1066105













              • Thank you for the fast reply! I am using MS SQL Management version 2014. Fieldquote is therefore not an option. I have changed the utilized quotechar, just as you stated, from pipe symbol ( | ) to double quotes ( " ). Data entries now look like this: AA, "BBB,BB", CC Nonetheless. I receive the same errors when trying to start the bulk insert as before.

                – M. Straube
                Dec 30 '18 at 17:46





















              • Thank you for the fast reply! I am using MS SQL Management version 2014. Fieldquote is therefore not an option. I have changed the utilized quotechar, just as you stated, from pipe symbol ( | ) to double quotes ( " ). Data entries now look like this: AA, "BBB,BB", CC Nonetheless. I receive the same errors when trying to start the bulk insert as before.

                – M. Straube
                Dec 30 '18 at 17:46



















              Thank you for the fast reply! I am using MS SQL Management version 2014. Fieldquote is therefore not an option. I have changed the utilized quotechar, just as you stated, from pipe symbol ( | ) to double quotes ( " ). Data entries now look like this: AA, "BBB,BB", CC Nonetheless. I receive the same errors when trying to start the bulk insert as before.

              – M. Straube
              Dec 30 '18 at 17:46







              Thank you for the fast reply! I am using MS SQL Management version 2014. Fieldquote is therefore not an option. I have changed the utilized quotechar, just as you stated, from pipe symbol ( | ) to double quotes ( " ). Data entries now look like this: AA, "BBB,BB", CC Nonetheless. I receive the same errors when trying to start the bulk insert as before.

              – M. Straube
              Dec 30 '18 at 17:46















              0














              You can try a format file: If you have applied quotes on your 2nd column...
              [csvfile] contains AAAAA,"B,BB",CCC



              Create Table csvfile
              (
              f1 VarChar(10),
              f2 VarChar(10),
              f3 VarChar(10)
              )

              BULK INSERT csvfile
              FROM 'c:downloadssample.csv'
              WITH (FORMATFILE = 'c:downloadssample.fmt');


              sample.fmt



              14.0
              3
              1 SQLCHAR 0 10 ","" 1 f1 SQL_Latin1_General_CP1_CI_AS
              2 SQLCHAR 0 10 ""," 2 f2 SQL_Latin1_General_CP1_CI_AS
              3 SQLCHAR 0 10 "rn" 3 f3 SQL_Latin1_General_CP1_CI_AS





              share|improve this answer






























                0














                You can try a format file: If you have applied quotes on your 2nd column...
                [csvfile] contains AAAAA,"B,BB",CCC



                Create Table csvfile
                (
                f1 VarChar(10),
                f2 VarChar(10),
                f3 VarChar(10)
                )

                BULK INSERT csvfile
                FROM 'c:downloadssample.csv'
                WITH (FORMATFILE = 'c:downloadssample.fmt');


                sample.fmt



                14.0
                3
                1 SQLCHAR 0 10 ","" 1 f1 SQL_Latin1_General_CP1_CI_AS
                2 SQLCHAR 0 10 ""," 2 f2 SQL_Latin1_General_CP1_CI_AS
                3 SQLCHAR 0 10 "rn" 3 f3 SQL_Latin1_General_CP1_CI_AS





                share|improve this answer




























                  0












                  0








                  0







                  You can try a format file: If you have applied quotes on your 2nd column...
                  [csvfile] contains AAAAA,"B,BB",CCC



                  Create Table csvfile
                  (
                  f1 VarChar(10),
                  f2 VarChar(10),
                  f3 VarChar(10)
                  )

                  BULK INSERT csvfile
                  FROM 'c:downloadssample.csv'
                  WITH (FORMATFILE = 'c:downloadssample.fmt');


                  sample.fmt



                  14.0
                  3
                  1 SQLCHAR 0 10 ","" 1 f1 SQL_Latin1_General_CP1_CI_AS
                  2 SQLCHAR 0 10 ""," 2 f2 SQL_Latin1_General_CP1_CI_AS
                  3 SQLCHAR 0 10 "rn" 3 f3 SQL_Latin1_General_CP1_CI_AS





                  share|improve this answer















                  You can try a format file: If you have applied quotes on your 2nd column...
                  [csvfile] contains AAAAA,"B,BB",CCC



                  Create Table csvfile
                  (
                  f1 VarChar(10),
                  f2 VarChar(10),
                  f3 VarChar(10)
                  )

                  BULK INSERT csvfile
                  FROM 'c:downloadssample.csv'
                  WITH (FORMATFILE = 'c:downloadssample.fmt');


                  sample.fmt



                  14.0
                  3
                  1 SQLCHAR 0 10 ","" 1 f1 SQL_Latin1_General_CP1_CI_AS
                  2 SQLCHAR 0 10 ""," 2 f2 SQL_Latin1_General_CP1_CI_AS
                  3 SQLCHAR 0 10 "rn" 3 f3 SQL_Latin1_General_CP1_CI_AS






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 30 '18 at 18:49

























                  answered Dec 30 '18 at 18:43









                  level3looperlevel3looper

                  56126




                  56126























                      0














                      Based on the answer of @Lukasz Skoda, I was able to find another solution.
                      I have set the delimiter to pipe ( | ) and the quotechar to ( " ). Thanks to everyone trying to help me!






                      share|improve this answer




























                        0














                        Based on the answer of @Lukasz Skoda, I was able to find another solution.
                        I have set the delimiter to pipe ( | ) and the quotechar to ( " ). Thanks to everyone trying to help me!






                        share|improve this answer


























                          0












                          0








                          0







                          Based on the answer of @Lukasz Skoda, I was able to find another solution.
                          I have set the delimiter to pipe ( | ) and the quotechar to ( " ). Thanks to everyone trying to help me!






                          share|improve this answer













                          Based on the answer of @Lukasz Skoda, I was able to find another solution.
                          I have set the delimiter to pipe ( | ) and the quotechar to ( " ). Thanks to everyone trying to help me!







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 30 '18 at 20:14









                          M. StraubeM. Straube

                          11




                          11






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979742%2fis-there-a-csv-quotechar-function-as-in-python-suitable-for-bulk-insert-into-ms%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Monofisismo

                              Angular Downloading a file using contenturl with Basic Authentication

                              Olmecas