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.
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, Doe222, Jane, Smith333, Bill, Tomas444, Anne, LewisI 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 RegardsBSR |
 |
|
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?? |
 |
|
SreenivasBora
Posting Yak Master
164 Posts |
Posted - 2006-06-26 : 14:50:36
|
Fastest way is BCP/BulkInsert than DTS. :-)With RegardsBSR |
 |
|
Trumb1mj
Starting Member
5 Posts |
Posted - 2006-06-26 : 14:52:09
|
are there any other viable options? |
 |
|
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 |
 |
|
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 |
 |
|
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 LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|