0

Hi,
I have a problem with reading a csv file with SQL server

UNH+ATOPHOEXEDI+AVLABL'
PLD+AII+RE11S'
TRV+1+40+DU03+MAN+LCA+20110706:0000:1'
ACC+1+SUNNY HILL HTL APTS ?+ POOL 3*:11113+:: PAPHOS+20110706+3:3 STAR++E:1:999'
PRC+A:825:3*C:0:1:15+9+5:2475:9:1BDR APT 2/4 INLAND VIEW+2:4++SC: SELF CATERING'
TRV+2+40+DU03+MAN+LCA+20110706:0000:7:N:20110713:0000'
ACC+2+SUNNY HILL HTL APTS ?+ POOL 3*:11113+:: PAPHOS+20110706+3:3 STAR++E:1:999'
PRC+A:4900:3*C:0:1:15+9+5:14700:9:1BDR APT 2/4 INLAND VIEW+2:4++SC: SELF CATERING'
.
.

ROWTERMINATOR is ' and fieldterminator +.
I have problem with column size.

Thank you

Edited by odysseous: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by BitBlt
0

I can see why you have problems. To begin with, it appears that the rows are of several different formats. In order to be able to parse all that you need to read row by row, make some logic choices and grouping breaks, and decide where each of the data in each row should wind up.

If you have some say in how the data is delivered to you, you might request that the deliverer give you the data in XML format. Then you can import it rather easily with OPENROWSET into a table with an XML column and use OPENXML to get the data out and put it in whatever relational tables you want.

If you have no control over how the data is delivered to you, I recommend you use a procedural programming language such as VB, or C/C++, or Java (depending on what you're most comfortable with) to read the file and build your logic that way. Trying to parse this using only TransactSQL or BCP would be pretty difficult.

Hope this helps!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.