Python Forum
python transfer Sql table to csv using BCP
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python transfer Sql table to csv using BCP
#1
Hi Team,

I am using below code for transfering data to CSV File,
code is working , But headers are missing .

can you please suggest how to include header in it.

from pathlib import Path
import subprocess

source_table = "xxx_xxxx_xxx_POC.dbo.Table1"
destination = str(Path("E:\test\table1.csv"))
subprocess.run(["bcp", source_table, "out", destination,  "-ABCD12345678\\ABCD5678,10010","-c", '-t"|"', "-T" ])
Reply
#2
https://stackoverflow.com/q/1355876/4046632
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Hi Buran,

I tried to check on given link, its hard to understand for me, I am new to coding.

Can I first transfer to sql data into csv files using BCP Transfer.

After that Can we insert headers at row 1.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  file transfer via python SFTP SCP mg24 3 3,007 Sep-15-2022, 04:20 AM
Last Post: mg24
  DNP3 file transfer with python Aussie 0 1,460 Sep-01-2020, 10:45 PM
Last Post: Aussie
  Python script that transfer it self iboman5 6 4,537 Nov-13-2017, 05:27 PM
Last Post: AceScottie
  Python script that transfer it self iboman5 2 3,057 Nov-10-2017, 06:56 PM
Last Post: iboman5

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020