Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BCP out without headers

Status
Not open for further replies.

jeffwest21

IS-IT--Management
Apr 4, 2013
60
GB
I need to create an export from my SQL 2005 database, i have the following

DECLARE @bcpCommand VARCHAR(8000)
SET @bcpCommand = 'bcp " SELECT * from ##TempExportData2" queryout'
SET @bcpCommand = @bcpCommand + ' ' + @fullFileName + ' -c -T -t"\",\"" -r"\"\n\"" -Usa -Psa '
EXEC Master..xp_cmdshell @bcpCommand

Which quite happily bcp's my data from my table out into a csv file and has quotes and commas in it, the issue is I want to do this without headers.

Is there a way that i can turn the headers off?

'Clever boy...'
 
Instead of using bcp, try using sqlcmd. sqlcmd allows you similar functionality, but you can suppress headers.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Just as I saw this i actually worked out it wasn't an issue with bcp it was an issue in my code which was adding the header row as a line in my table as well DOH!!

Although I do have another issue in that i have got a quote around all the fields except the start of the first on

19/09/2013 16:35","2013-09-19 16:35:01",

Which is ever so slightly annoying

This is the bcp out command, where am I missing the quote from to get it at the start??
SET @bcpCommand = @bcpCommand + ' ' + @fullFileName + ' -c -T -t"\",\"" -r"\"\n\"" -Usa -Psa'

'Clever boy...'
 
A minor note, but the "-T" and the "-Usa -Psa" are mutually exclusive. The trusted connection will take precedence, so you should be able to take out the "-Usa -Psa".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top