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 2008 Forums
 Transact-SQL (2008)
 Importing multiple files

Author  Topic 

Bex
Aged Yak Warrior

580 Posts

Posted - 2012-01-23 : 10:47:55
I want to import multiple files into a DB. Do either BULK INSERT or OPENROWSET allow files to be treated like tables so that I can query them in order to join the results and select out as a query?

E.g. File1 contains Orders and File2 contains OrderItems.

I want to export file2 but join on file1 on the natural key?

Also, another potential requirement:

E.g. File1 constains all Order, Items and Tenders. I want to select each as a separate query: Select * from file1 where Type = H. Again, how do I do this?

Thanks

Hearty head pats

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-23 : 14:06:17
You can probably treat OPENROWSET like a table, but not BULKINSERT (unless of course, you insert into a table and then join with that table). If you post the queries you are trying, some of the people on the forum may be able to suggest changes to make it work.
Go to Top of Page

Bex
Aged Yak Warrior

580 Posts

Posted - 2012-01-24 : 04:08:04
Hi Sunita

Thanks for the reply. I ended up using OPENROWSET and that seemed to do the job :)

Hearty head pats
Go to Top of Page
   

- Advertisement -