I have created a stored procedure that produces output for specific tables in our database. The output for one of the files is garbled. I have to have it fixed.
The strategy I'm employing is to first create a view that contains a select statement that chooses all the fields in the table; i.e., select field1, field2, field3, etc. Then my routine calls BCP by selecting from the view. My command resembles this:
bcp "select * from Database.OurSchema.BCP_View" queryout "c:\temp\bcp\MyTable.CSV" -SSQLServerName -t"|" -r"" -T -c
Note: the "r" parameter is actually: -r Quote Backslash n Quote
I have been painstakingly adding one field at a time to the view until the output becomes garbled. When it does, I skip that field and try to add the one following. The same result occurs; the output is garbled.
This suggests that there is a limit to the number of fields BCP can be used for. Add one more to the limit and you get junk.
This table has a lot of null data. However, It is fine with null data up until it reaches the point where the data becomes garbled. Also, there is no unusual characters in string fields of this table at all.
I've been searching for an option to fix this matter without success. Does anyone have an idea how to use BCP to produce non-garbled output for a table with many fields?