Bulk Insert with other requirements..
Hi guys, I have a code here that inserts a .csv file to an sql server 2005 database.
Code:
Bulk insert Sampletb
from 'C:\Sample\Sample.csv'
with
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
But it directly inserts all the contents of the file to the database.. Want I want to do is to call the Ids from a different table and insert it instead of the name in the a certain field.
Example:
Code:
-Sample.csv-
Name City Type
==== ==== ====
Name1 City1 Type1
Name2 City2 Type2
-Typetb (in the database)-
TypeId Type
===== ====
1 Type1
2 Type2
3 Type3
-Sampletb(When inserted to the database)-
Id Name City Type
==== ==== ==== ====
1 Name1 City1 1
2 Name2 City2 2
Any ideas?? Thanks.
yangski, August 11th, 2009 12:11 AM
Bookmarks