Solved

SQL BCP exporting to ASCII

Posted on 2014-07-25
3
406 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 32

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 32

Accepted Solution

by:
ste5an earned 500 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

757 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now