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
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Batch insertion

Author  Topic 

Trumb1mj
Starting Member

5 Posts

Posted - 2006-06-26 : 14:22:53
I am working on a problem for work in which I need to insert into a table. The problem is I want to be able to have a general insert statement that looks at a text file for the specific information for insertion. Here is an example of what I’m talking about:


INSERT INTO “Student”
(ID, First, Last)
Values(possibly variables here???)


The text file would look like this:


111, Michael, Doe
222, Jane, Smith
333, Bill, Tomas
444, Anne, Lewis



I want a function to search through this file and insert the values. Can anyone help me with this?

SreenivasBora
Posting Yak Master

164 Posts

Posted - 2006-06-26 : 14:46:08
Try with bcp / Bulk Insert. See Books online for more help.

With Regards
BSR
Go to Top of Page

Trumb1mj
Starting Member

5 Posts

Posted - 2006-06-26 : 14:49:45
Thanks of the tip. I have thought of bcp and this will work. I want to be able to do this all from the query analyzer however. Any other tips??
Go to Top of Page

SreenivasBora
Posting Yak Master

164 Posts

Posted - 2006-06-26 : 14:50:36
Fastest way is BCP/BulkInsert than DTS. :-)

With Regards
BSR
Go to Top of Page

Trumb1mj
Starting Member

5 Posts

Posted - 2006-06-26 : 14:52:09
are there any other viable options?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-06-27 : 00:08:34
"I want to be able to do this all from the query analyzer however"

You can't import a text file from Query Analyser (well you can, but only by using QA to launch a "job" on the Server)

To bulk load a table you need to use BCP, DTS or build something that imports XML, or parses a large TEXT - e.g. to Split a CSV TEXT.

You could also format your text file as INSERT statements, but I don't think that is a very good idea and it would be dog slow anyway!

Kristen
Go to Top of Page

CSK
Constraint Violating Yak Guru

489 Posts

Posted - 2006-06-27 : 00:17:43
Why not Bulk Insert. I am also struggled with the same problem in last week, Kristen suggetsed the BCP/Bulk insert. try tat One

-- KK
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-06-27 : 00:47:50
Openrowset is an excellent way to accomplish this ad-hoc.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -