Solved

SQL BCP exporting to ASCII

Posted on 2014-07-25
3
413 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 33

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 33

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

867 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

21 Experts available now in Live!

Get 1:1 Help Now