Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL BCP exporting to ASCII

Posted on 2014-07-25
3
Medium Priority
?
481 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

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 35

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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?
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

670 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