Unix Technical Forum

TransferText dropping fractions

This is a discussion on TransferText dropping fractions within the SQL Server forums, part of the Microsoft SQL Server category; --> thanks for the 'Tough Love'.. I modified the BULK INSERT to : BULK INSERT dbo.tmpPaTimeClock FROM Path... WITH (DATAFILETYPE ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 02-29-2008, 02:20 PM
ckirby@mindspring.com
 
Posts: n/a
Default Re: TransferText dropping fractions

thanks for the 'Tough Love'.. I modified the BULK INSERT to :

BULK INSERT dbo.tmpPaTimeClock
FROM Path... WITH (DATAFILETYPE = 'char',
, FIRSTROW = 3
, FIELDTERMINATOR = ','
, ROWTERMINATOR = '\n')

and that did the trick. It splits the first column in 2 because of the
comma seperating the names, but that's really not a problem for me,
since I'm not using that field(s). But if anyone know how to prevent
that , I'd like to learn.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 02-29-2008, 02:20 PM
ckirby@mindspring.com
 
Posts: n/a
Default Re: TransferText dropping fractions

I spoke too soon. The name field isn't uniform, some records have the
double quotes around it, with a comma splitting the name, others don't,
so those are throwing the columns off by one.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 02-29-2008, 02:21 PM
Erland Sommarskog
 
Posts: n/a
Default Re: TransferText dropping fractions

(ckirby@mindspring.com) writes:
> I spoke too soon. The name field isn't uniform, some records have the
> double quotes around it, with a comma splitting the name, others don't,
> so those are throwing the columns off by one.


That's when you need a format file. The good news is that the format file
will drop your column headers as well.

The format file for the full file is kind of boring, so I only give an
example for a file with 5 fields, where the first is quoted, and the rest
is not. (Indendation is for formatting of the post only. All text starts
in column 1.)

8.0
6
1 SQLCHAR 0 0 "\"" 0 "" ""
2 SQLCHAR 0 0 "\"," 1 col1 ""
3 SQLCHAR 0 0 "," 2 col1 ""
4 SQLCHAR 0 0 "," 3 col1 ""
5 SQLCHAR 0 0 "," 4 col1 ""
6 SQLCHAR 0 0 "\r\n" 5 col1 ""

The trick here is that we define the file as having six field - there is
an empty field before the first quote. SQLCHAR is the datatype in the
file, and since this is a text file, everything is SQLCHAR. (Or SQLNCHAR
if it is a Unicode file.) The next two columns are for binary files,
and fixed-length fields. The comes the field terminator. Notice that
BCP does not really have a notion of a row terminator; the row terminator
is just the field terminator for the field.

The column that reads 0 1 2 3 4 5 is the mapping to the table columns.
0 means that that field is not imported. 1 is the first field etc. Next
column is for table-column names, but that's informational only. Finally,
the last column is where you can specify collation.

Note that the first record as far as BCP is concerned, consists of the
column headers + the first data row. The first field of the first row,
is everything up to the first ".

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:06 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com