I am trying to use the MS SQL Server 2005 Import/Export tool to export a table so I can import it into another database for archival. One of the columns is text so if I export as comma-delimited, when I try to import it into the archive table, it doesn't work correctly for rows with commas in that field. What options should I choose to ensure my import will work correctly?
Use quotes as text qualifier
Text qualifier: Type the text qualifier to use. For example, you can specify that each text column be surrounded with quotation marks.
I never use the comma delimter unless the client requires it. Try using | as a delimter. YOu can also use the text qualifier if need be.
I just found this, and it's describing my exact problem, that commas are breaking up the data when I export from MSSQL to a text file. Actually, it's a CSV file, if that makes any difference. But even when I change the Column Delimeter to a | or anything, when I look at the file afterwards, in each instance in my text field where a comma exists, the CSV file splits it into a whole new column. The new delimeters are there for other fields, but why can't I make commas not break everything?
Thanks,
-Rick
Over a year later, I now have an ideal solution to my data export needs, thanks to http://stackoverflow.com/questions/20363/
bcp "SELECT * FROM CustomerTable" queryout "c:\temp\CustomerTable.bcp" -N -S SOURCESERVERNAME -T
bcp TargetDatabaseTable in "c:\temp\CustomerTable.bcp" -N -S TARGETSERVERNAME -T -E
- -N use native types
- -T use the trusted connection
- -S ServerName
- -E Keep identity values specified in the data file
Very quick and easy to embed within code.