Hi Vmurali,This is one of those problems where the solution is totally and annoyingly complex. What you will have to do is to use a custom format file. Here is my example SQL setupCREATE TABLE _foo ( [Fname] VARCHAR(255) , [Lname] VARCHAR(255) , [Address] VARCHAR(255) , [Phone] VARCHAR(255) , [Notes] VARCHAR(255) ) INSERT _foo ( [Fname] , [Lname] , [Address] , [Phone] , [Notes] ) SELECT 'foo', 'bar', '1, 23 Av', '223123', '123123'UNION SELECT 'aaa', 'bbb', 'ccccc', 'dddd', 'eeee'
This makes the table _foo in my database with the fields that you specified.Here's the bcp command that I'm usingbcp "SELECT TOP 10 '\"',* FROM CS_FLEX234_SONY.dbo._foo" QUERYOUT dump.csv -t\",\" -r\"\n -SDEVDB2\SQLSERVER2005 -Usa -Pmuppet -fbcp.fmt
And finally -- here's my bcp.fmt file9.061 SQLCHAR 0 0 "" 1 FirstQuote SQL_Latin1_General_CP1_CI_AS2 SQLCHAR 0 255 "\",\"" 2 Fname SQL_Latin1_General_CP1_CI_AS3 SQLCHAR 0 255 "\",\"" 3 Lname SQL_Latin1_General_CP1_CI_AS4 SQLCHAR 0 255 "\",\"" 4 Address SQL_Latin1_General_CP1_CI_AS5 SQLCHAR 0 255 "\",\"" 5 Phone SQL_Latin1_General_CP1_CI_AS6 SQLCHAR 0 255 "\"\r\n" 6 Notes SQL_Latin1_General_CP1_CI_AS
What this does is1) Selects a " as the first column returned.2) The format file treats the column terminator for that first column as <nothing> therefore the second column gets concatenated onto the first (the quote).3) format file for other column terminators is "," (so getting " round each other elmenet4) row teminator is " <newline>the output I get is this"foo","bar","1, 23 Av","223123","123123""aaa","bbb","ccccc","dddd","eeee"
BCP takes a little getting your head around sometime!Hope this helps you out.NB: edited due to typo(s)Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION