Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL BCP exporting to ASCII

Posted on 2014-07-25
3
Medium Priority
?
503 Views
Last Modified: 2014-07-25
Hi

I am trying to export data from an SQL table using BCP using the script below:

select @sql = 'bcp "exec bloc700dummy.dbo.reptoolGetCustomers @Salesman = MS" queryout "C:\Reptool\CustomerMS.txt" -T -c -S'

The resultant datafile is then used as data for a dropdown within a VB.Net application. I have an issue where if a data column within the SQL table contains nothing, it is exported as what apperas to be 0X0 which I believe is HEX for a space. The problem I have is that when I try to concatenate fields of data together (address details), as soon as an empty field is encountered, any data after that field is lost!

Can anyone advise if there is a different switch combination I can use within BCP to stop this happening or can I code around this within my application?

Many thanks

Steve
0
Comment
Question by:abmcsltd
  • 2
3 Comments
 
LVL 36

Expert Comment

by:ste5an
ID: 40219430
Nope. 0x0 is NUL. This has an undefined meaning in the context of an ASCII file. It has not character representation. E.g. in many languages the byte 0x0 indicates the end of a string. Thus your "data loss".

Use COALESCE(yourColumn, '') to return non-null, but empty values.
0
 

Author Comment

by:abmcsltd
ID: 40219449
Hi

Where do I use this....is it part of the BCP script?

Thanks

Steve
0
 
LVL 36

Accepted Solution

by:
ste5an earned 2000 total points
ID: 40219452
Well, no. You need either to adjust the procedure or embed in a SQL script used for BCP.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question