importing fixed width files with 80 fields


Here is the situation. Using the import tool, I have to define 80 fields in order to import the flat file data into my db table. I problem is that I have to define 80 fields for my fixed width file. Do any of you have a better and quicker way of doing this?
LVL 1
jorbroniAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pivarCommented:
Hi,

You could create an schema.ini file, see
http://msdn.microsoft.com/en-us/library/windows/desktop/ms709353(v=vs.85).aspx
so you don't have to recreate the definition every time.

Example schema.ini:

[test.txt]
Format=FixedLength
ColNameHeader=False
MaxScanRows=0
Col1=col1 Text Width 4
Col2=col2 Text Width 4
Col3=col3 Text Width 4

Open in new window


I'm not sure if it works with flat file source though, but if you have a text-driver that might work.

Otherwise you could run an INSERT like this

INSERT INTO yourtable
SELECT * 
FROM   OPENROWSET('MSDASQL', 
   'Driver={Microsoft Access Text Driver (*.txt, *.csv)};DefaultDir=d:\;', 
   'SELECT * FROM test.txt;' 
) 

Open in new window


/peter
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.