May 13, 2008 at 3:47 pm
I am trying to update a table with store information for thousands of stores. I was given a file with the information to update. Some of those entries in the file are not in the database, so there I have to an insert record. What is the easiest way to do this to write a script to update just the records that need updating and inserting new records in one script? Thanks.
May 13, 2008 at 5:48 pm
If you do not like cursor, you may do it as below.
1. Make a temporary tabe;
2. Populate data on it;
3. Retrieve new data by comparing the new table and the existing;
4. Insert into the new table.
May 13, 2008 at 5:56 pm
UPDATE A
SET ....
FROM TableA A
INNER JOIN TableB B ON B.KeyCol = A.KeyCol
INSERT INTO TableA
(columns list)
SELECT B.Columns list
FROM TableB B
WHERE NOT EXISTS (
select 1 from TableA A where B.KeyCol = A.KeyCol)
_____________
Code for TallyGenerator
May 15, 2008 at 2:12 pm
Thanks folks,
The idea and the SQL provided helped
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply