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.
Here is some code in case anyone needs it:
insert into usr.SourceTable with auto name WITH IMPORTED AS ( select MYROW from openstring( FILE 'C:\\\\myfile.txt') WITH ( MYROW long varchar ) OPTION (DELIMITED BY 'STRINGNEVERTOBEFOUND') as ImportedSub ) SELECT SUBSTRING(IMPORTED.MYROW,0,13) AS Col1 , SUBSTRING(IMPORTED.MYROW,13,5) AS Col2 , SUBSTRING(IMPORTED.MYROW,18,7) AS Col3 FROM IMPORTED;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| 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.