on ‎2012 Apr 27 2:04 PM
I have some fixed-width files that I need to extract data from. Each record is a new line, but the columns are fixed-width.
I have a statement that works correctly when I run it in ISQL using the
input into mytable from 'c:\\myfile.txt' format fixed column widths (5,1,3,7);
I would like to capture the task in a procedure so I can run it multiple times against various files without running ISQL.
The input statement is only available in ISQL, so what are my options for loading the fixed-width type of files from within a procedure? I am guessing LOAD TABLE but how specifically to get LOAD TABLE to parse the fixed-widths and any other advice is appreciated.
Request clarification before answering.
Rather than LOAD TABLE, you could use an INSERT ... FROM SELECT that uses OPENSTRING over the file. This is somewhat dependent on the size of the file - it won't be efficient for very large files. However, Once you have the file's contents available to a query, you can then use SUBSTRING() to chunk off the appropriate pieces and use those sub-expressions for the INSERT.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You could certainly do that, Volker, to work around the issues of the fixed-format file. It doesn't avoid the transaction log overhead, however, of the subsequent INSERT statement.
| User | Count |
|---|---|
| 13 | |
| 8 | |
| 7 | |
| 5 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.