Showing posts with label everybody. Show all posts
Showing posts with label everybody. Show all posts

Thursday, March 8, 2012

compare and update a table from one database to another table on another databas

Hi everybody.. need help on this situation which i am to.

I have two databases named db1 and db2
both of which has two identical tables named tbl1 and tbl2

I need to compare tbl1 of db1 to the tbl2 of db2
if there is a record that is existing on tbl1 and not on the tbl2 then
i need to create a tblnew on db2
from that tblnew then i need to append all the data from tblnew to tbl2 of db2.

I don't know how to start with it because i'm used to appending data on two tables on the same database but not on a different one...

thanks
alexStart here or read BOL about 4 part naming:

http://mssqltips.com/tip.asp?tip=1095|||Are the databases on the same server? Or Different Server or Instance?

In any case, read this

http://weblogs.sqlteam.com/brettk/archive/2004/04/23/1281.aspx|||on the same server

thanks

compare a table with a file.

Hi everybody (yet another newbie :))

I have a table with 12,000 rows. I also have a file with 15,000 rows.

One of the columns of the table has the field oid and that 7 digit number exists in the file with the 15,000 rows. I need to filter the file (15k rows) to the size of the table. Whenever the oid exists in the table I keep the row or whenever the oid filed does not exist in the table I drop the row off the file. I can extract the oid off the table but then I have to bash it the same way with file with the 15k rows. Is it better to do it in SQL or should I shellscript it between the two files? (in that case I should really post in the shellscript forums)

thanks for helping out.

NickFirst u load the flatfile in to a temporary table and use a delete statement to remove the non matching records from teh temp table

Then again export the data from the temp table to flat file.

If Original table is T1 & tmp table is T2

delete from t2 where oid not in (select oid from t1)|||0002020002.000000008P0000000020031217142337CD N0100000226227884000020560116431834 00010001

0002020002.000000008P0000000020031217142337CD N0100000226227884000020550118641512 00010001

Thank you sir :)
Ok I was thinking about it and this is what I thought as well.

Now here is a copy of the content of the flat file:

0002020002.000000008P0000000020031217142337CD N0100000226227884000020560116431834 00010001

(this is one line it may wrap in the post). I am kind of green on SQL loader and I am niot sure how to apprach this. 560116431834 is the oid filed that I am interested. can you substr the SQL loader on character position like in sql?

thanks a million for your help.

Nick|||you could spool the required feild instead to the file...

with the required set options ...

thanks...