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 2000 Forums
 Transact-SQL (2000)
 Bulk update a table using a flat file- sql server

Author  Topic 

bpuccha
Starting Member

34 Posts

Posted - 2012-06-08 : 10:05:16
Hi,

I have to bulk update my table "a" using a flat file Flatfile.txt


Table a:
ID name add1 add2 phone_no
1 aaaa test1 test2 123456789
2 bbbb test3 test4 576878979
3 cccc test5 test6 683789790
4 dddd test7 test8 687978980

Flatfile.txt

id name phone_no
3 XXXXX 6548584978
4 zzzzz 954759084

here I have to update the rows with id 3 and 4 with changed name and phone no in the table a..So output should be like this

Table a:
ID name add1 add2 phone_no
1 aaaa test1 test2 123456789
2 bbbb test3 test4 576878979
3 XXXXX test5 test6 6548584978
4 zzzzz test7 test8 954759084

One way is to insert the data from a flat file to a table and update the table a by joining the tables.

Is there any other way?

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-06-08 : 11:44:37
You could join in an ssis package to do the updates before the inserrt - or output the result to a file if that is the destination.
Importing to a table allows you to see what is going on though.

Oh v2000 - not sure if DTS can cope with that - probably not a good idea even if it can.
I would bulk insert, update, bcp out if necessary. It's by far the simplest method and would be might default on any version - would need a reason to use anything else.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

bpuccha
Starting Member

34 Posts

Posted - 2012-06-08 : 12:05:32
What is OPENROWSET? What does it do?
Go to Top of Page

bpuccha
Starting Member

34 Posts

Posted - 2012-06-08 : 12:31:15
Actually me scenario is...

I have a Java code where i am updating the table, If the updation fails I will keep that row in a text file, at last I have to bulk update the table for the failed rows once.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-08 : 12:34:10
quote:
Originally posted by bpuccha

Actually me scenario is...

I have a Java code where i am updating the table, If the updation fails I will keep that row in a text file, at last I have to bulk update the table for the failed rows once.



see

http://www.databasejournal.com/features/mssql/article.php/3331881/OpenRowSource-and-OpenRowSet-in-SQL-Server-2000.htm

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -