[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Vertical File into a Horizontal SQL Table

Posted on 2012-03-26
8
Medium Priority
?
362 Views
Last Modified: 2012-03-30
All-

I have an issue where I am trying to import a flat file that is set up vertically and I need to set up a table in SQL.  I have provided a couple of some test data.  Any direction would be appreciated, I would prefer to handle this via a DTS package to collect the file and import it directly into a table.

Thanks…
Test-Data-for-EE.txt
0
Comment
Question by:GPCDIADMIN
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 9

Expert Comment

by:OCDan
ID: 37767947
What do you want your resultant table to look like?

p.s. that is one ugly ass flat file, whatever happened to commas :D
0
 

Author Comment

by:GPCDIADMIN
ID: 37768112
I would like Columns to be

ISA
GS
ST
BEG
REF
DTM
TD5
N9
MSG
N1
N3
N4
PER
PO1
PID
MSG
TXI
CTT
SE
GE
IEA


Thanks...
0
 
LVL 9

Expert Comment

by:OCDan
ID: 37768140
Someone else may have an answer but there doesn't seem to be any common delimeters to me so creating a generic script would be damn near impossible.

You could hardcode some charindex code in there but again given the lack of continuity searching for 2-4 characters would likely result in a lot of anomalous results.

Can you get that flat file changed at all? Are you sent this or are you creating this yourself?
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

Author Comment

by:GPCDIADMIN
ID: 37768644
I am using an AS/2 connector to collect the files, I do not have control of changing the file format.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 37769523
Ah yes, the infamous EDI format.  I would suggest you build an application using .NET to handle this.

>>I would like Columns to be <<
Unless you use very generic varchar columns allowing for the maximum length you will not be able to do this.
0
 
LVL 3

Expert Comment

by:tsnirone
ID: 37770704
As long as the files you receive conforms to a standard where you can "divide" the input into columns (Seems the "~" is columnseparator(?) - is this X12?) I see no problem in importing this data into a table and massage it in (ie) stored procedure to your liking...
0
 

Author Comment

by:GPCDIADMIN
ID: 37771305
Correct this is X12 style, I had some thoughts last night I am going to try out.  It will be lengthy but I wanted to see if anyone has done this before through a DTS or SQL in general.
0
 
LVL 3

Accepted Solution

by:
tsnirone earned 1500 total points
ID: 37773851
I tried to search to find a stored procedure for you that you could alter/build on but was unsuccessful :(

In a stored procedure tho, you can do just about anything, so I'd import the data into a temp-file and go (lengthy) from there.

Good luck :)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question