473,386 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Use Bulk Insert Statement with JOIN !!

2
Hi,

I have two tables. Employees and departments as follows:

Employees
- Name
- Salary
- Department ID


Departments
-Department ID
-Department Name


Now what I am doing is that I am allowing the user to give me a CSV file with all the employees data to bulk insert it in the table Employees as follows:

Employee Name,Salary,Department Name


The problem is that the users know nothing about the department ID. So what they type in the CSV ffile as you can see above is the department name.

The SQL statement I normally use for bulk insert is:

Expand|Select|Wrap|Line Numbers
  1. BULK INSERT CAS.dbo.employees
  2. FROM 'c:\list.csv' WITH 
  3. (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' )
My question is, how can I use the same technique but insert the departments IDs not name as in the CSV file.!!!!

Appreciate your helps.
Thanks
Sep 1 '07 #1
2 2909
azimmer
200 Expert 100+
Hi,

I have two tables. Employees and departments as follows:

Employees
- Name
- Salary
- Department ID


Departments
-Department ID
-Department Name


Now what I am doing is that I am allowing the user to give me a CSV file with all the employees data to bulk insert it in the table Employees as follows:

Employee Name,Salary,Department Name


The problem is that the users know nothing about the department ID. So what they type in the CSV ffile as you can see above is the department name.

The SQL statement I normally use for bulk insert is:

Expand|Select|Wrap|Line Numbers
  1. BULK INSERT CAS.dbo.employees
  2. FROM 'c:\list.csv' WITH 
  3. (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' )
My question is, how can I use the same technique but insert the departments IDs not name as in the CSV file.!!!!

Appreciate your helps.
Thanks
Though I'm not a BULK INSERT expert, I'd use a temp table: bulk insert into the temp table and either process it after the bulk insert is complete or put an insert trigger on the temp table that throws the inserted rows right over to the other table.

Others may be more experienced on this than me, though.
Sep 1 '07 #2
ck9663
2,878 Expert 2GB
Though I'm not a BULK INSERT expert, I'd use a temp table: bulk insert into the temp table and either process it after the bulk insert is complete or put an insert trigger on the temp table that throws the inserted rows right over to the other table.

Others may be more experienced on this than me, though.

i second the motion...upload it to some table. prepare all the data you need. then populated whatever table needs to be updated
Sep 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: php newbie | last post by:
Hello, I am trying to load a simple tab-delimited data file to SQL Server. I created a format file to go with it, since the data file differs from the destination table in number of columns. ...
20
by: akej via SQLMonster.com | last post by:
Hi, i have table with 15 columns CREATE TABLE . ( PRIMARY KEY , NULL , NULL , NULL , NULL , (50) NULL , NULL
6
by: pk | last post by:
Sorry for the piece-by-piece nature of this post, I moved it from a dormant group to this one and it was 3 separate posts in the other group. Anyway... I'm trying to bulk insert a text file of...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
10
by: Daniel P. | last post by:
How can I use ADO.NET to insert lots of records in a very fast way? Thanks!
1
by: Metal Dave | last post by:
I do not understand the error handling of SQL Server here. Any error in bulk insert seems to halt the current T-SQL statement entirely, rendering it impossible to log an error. The first statement...
2
by: Ted | last post by:
I have BULK INSERT T-SQL statements that work for all of my basic data tables except for one. Here is the problem statement (with obvious replacement of irrelevant path info): BULK INSERT...
0
by: ozkhillscovington | last post by:
We have sp's in place that do BULK INSERTS from txt files into the tables. This works fine, however they have asked us to add a field that identifies accounting ctr. The only thing that identifies...
0
by: rshivaraman | last post by:
BULK INSERT bill_tbl FROM 'd:\ftp_Data\in\baddress.dat' WITH ( FIELDTERMINATOR = ';', ROWTERMINATOR = '\n' ) --------------------------------- This is the query used to populate bill_tbl....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.