Python Forum

Full Version: python transfer Sql table to csv using BCP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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" ])
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.