Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 [bcp] Exporting data WITHOUT field terminator

Author  Topic 

RaiausderDose
Starting Member

2 Posts

Posted - 2010-04-01 : 08:17:07
Hi!

How do I export tables / queries WITHOUT using a field terminator at all?

bcp "SELECT * FROM XYZ" -T -S myserver -c -t\0
results in a file with 2008NULSADSQWENUL etc.
But I would like to have NO terminator at all :) no space, no tab and no NUL just nothing.
'... -t"" ' uses tab again.

If I used a formatfile
like this:
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="3" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>

it will, of course, result in a space and TERMINATOR="" produces an compling error.
Is there a way to use no columnseperator at all?

This is the result with the default seperator:
2008 101300129 Eab3Xlt 1

Want I need should look this:
2008101300129Eab3Xlt1

Thanks for you time and help!

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-01 : 09:44:25
Make a concatenation of all required columns and then you can export this one big column.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-01 : 13:26:49
To elaborate on what webfred said, create a view that puts concatenates all columns together and then bcp out the view. You'll need to add conversions in the view for numeric data and other data types that are not character based.

Here's an example:

CREATE VIEW View1
AS
SELECT Column1 + Column2 + Column3 + CONVERT(varchar(10), Column4) AS ConcatColumn
FROM YourTable
GO

bcp db1.dbo.View1 out C:\temp\bcp.txt -c -Sserver1\instance1 -T -r\r\n

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -