|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
load flat file with DTS question
I have text files (fixed length) downloaded from an AS400 system. I try and use DTS to load the files to a table in SQL 2000 but what ends up happening when I'm using DTS is the field positions get knocked off by several positions. The flat file is almost 300 characters wide. So you can imagine by the time I get to the end of the file how screwed up everything is and it gets very difficult to match up the field names with the file layout. Currently I need every field in the flat.
Does anyone have ideas on how to load a very wide file into SQL without running into this mess? |
|
#2
|
|||
|
|||
|
RE: load flat file with DTS question
What are your data field separated by?
|
|
#3
|
|||
|
|||
|
RE: load flat file with DTS question
something like this might help:
----------------------- $hfile = fopen ($dloadFile, "r"); while (!feof($hFile)) { $buffer = fread ($hFile, 4096); $fields = explode ($delimiter, $buffer); $sql = "insert into table values ("; $firstLoop = true; foreach ($fields as $value) { if (!$firstLoop) { $sql .= ","; } $firstLoop = false; $sql .= "'" . $value . "'"; } $sql .= ")"; $rs = mssql_query ($sql, $dbLink); } ----------------- This code assumes the following: a) You will add in error checking b) The table fields are in the same order as the fields in the file c) You will supply the dbLink, delimiter and dloadFile variable values Without any more info, that's about the best I can do. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > load flat file with DTS question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|