Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to import records to table

Author  Topic 

AdamWest
Constraint Violating Yak Guru

360 Posts

Posted - 2012-03-07 : 09:20:44
I have been only importing an entire database. I have one table I have to add to a database. We have the records as flat files and i have creates the columns for this. Now how do I get this into the table? It's about 10 mill records. the thing is also, I only need about 1/7 of them if they are 'price type 15'.

They would not fit in an excel. they are sitting in word pad.

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-07 : 09:27:53
what format are they in? What's the record layout. Can you post some sample data. What platform are you on?

You can use bcp, BULK INSERT, SSIS..and there are a variety of other hacks



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

AdamWest
Constraint Violating Yak Guru

360 Posts

Posted - 2012-03-07 : 11:12:24
its flat file here
64253033335072000100400000074200
64253033335082000100400000371000
64253033335152000100400000074200
64253033335162000100400000371000
64253033335172000100400000074200
64253033335182000100400000371000

i have a table ready to receive it.
but for some reason this doesn't find

BULK INSERT PBM_Price_FDB
FROM 'C:\NDC_PRICE.txt'

Msg 4860, Level 16, State 1, Line 1
Cannot bulk load. The file "C:\NDC_PRICE.txt" does not exist.

but i know its there.

quote:
Originally posted by X002548

what format are they in? What's the record layout. Can you post some sample data. What platform are you on?

You can use bcp, BULK INSERT, SSIS..and there are a variety of other hacks



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/




Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-07 : 11:18:14
The file must be on the server, not your local drive

I guess you could set it up as unc...but I would advice against loading across a network

But in any case, your file is not delimited so you will need to know the layout of your file and create a format file

Or load it to a single column table and use substring to parse it out. That has the advantage of doing audits against the data before you insert it into it's final resting place

capisce?





Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-03-07 : 11:22:04
That error message sounds almost like it is exactly the issue Brett identified - that the file must be in the C: drive on the SERVER, not on the C: drive of the client box where you are running SSMS.

You can try couple of things:
1. Use UNC path instead of drive letter+name
2. Check whether the login that you are using to do the bulk insert has access to the location where the file is stored.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-07 : 11:23:21
quote:
Originally posted by sunitabeck

That error message sounds almost like it is exactly the issue Brett identified - that the file must be in the C: drive on the SERVER, not on the C: drive of the client box where you are running SSMS.

You can try couple of things:
1. Use UNC path instead of drive letter+name
2. Check whether the login that you are using to do the bulk insert has access to the location where the file is stored.



Like I said...not across the network...unless you plan to be trhere for days, and don't mind a hiccup or 2



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

AdamWest
Constraint Violating Yak Guru

360 Posts

Posted - 2012-03-07 : 11:26:48
OK I got the file in as one string.
Can I parse it out to another table so I can pick out the type 15 ones?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-07 : 11:46:53
ABSolutely

SELECT SUBSTRING(Col,s,l) AS Col1
FROM Table

Do you have any columns that are numeric or date/datetime?

You can check for validity with ISDATE and ISNUMERIC

Do you have any FK Relationships that need to be checked?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -