Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

BCP command to export data to excel with column headers

By Samardeep Khera,

Be careful for following lines

replace <element> with your local environment elements

remove "<" ," >" signs

e.g. use master

1 use <database>

8 @dbName varchar(100) = '<database name>',

9 @sql varchar(8000) = 'select <col1,col2,col3....col4> from <table>',

10 @fullFileName varchar(100) = '<output file path>'

57 SET @bcpCommand = @bcpCommand + ' C:\Temp\test.csv -c -w -T -U sa -P sa","-CRAW'
58 EXEC <database>..xp_cmdshell @bcpCommand

 

 

Total article views: 3307 | Views in the last 30 days: 3
 
Related Articles
FORUM

Difference between varchar(max) and varchar(8000)

Difference between varchar(max) and varchar(8000)

FORUM

VARCHAR(x) VS VARCHAR(MAX)

any downside to VARCHAR(MAX)?

FORUM

Regarding using VARCHAR(MAX)

Usage of VARCHAR(MAX)

FORUM

varchar issue

varchar issue

FORUM

Tricky ...VARCHAR

VARCHAR logics

 
Contribute