question

athar_anis avatar image
athar_anis asked

merge identical tables

**I have asked this question [Here Too][1]** I have two tables in sql server 2008 R2. one table has records as follows, this table is called ASTM_Table ![alt text][2] and another table called ASTM1 is like this ![alt text][3] Astm1 table contains gravity with 0.1 difference while "astm_table" has gravity with a difference of 0.5 (However, this table is the latest) All i want is to have all those records from astm1 table and merge them in astm_table, but only those records that are not available in astm_table. For example, in astm_table, gravity 54.1, 54.2, 54.3, 54.4, 54.6, 54.7, 54.8, 54.9 are not available. so i want to get these values from astm1 table and copy them in astm_table. is it possible and yes then which query would do the job right? Please Help [1]: http://stackoverflow.com/questions/11498072/merge-two-identical-tables [2]: /storage/temp/307-astm_tables.jpg [3]: /storage/temp/308-astm1.jpg
sql-server-2008query
astm_tables.jpg (66.8 KiB)
astm1.jpg (76.5 KiB)
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Usman Butt avatar image Usman Butt commented ·
You have already got some answers there, how about them?
0 Likes 0 ·
athar_anis avatar image athar_anis commented ·
yes, i resolved it. I have also entered the query here in case anybody needs help
0 Likes 0 ·

1 Answer

·
athar_anis avatar image
athar_anis answered
yeah resolved... Here is what i got use astm go INSERT INTO ASTM_Tables (Table_No,Temperature,Gravity,Result) SELECT TBLE, TEMPR, GRV_OB, GRV_SP FROM ASTM1 WHERE tble = '5a' and not EXISTS(SELECT * FROM ASTM_Tables X WHERE X.Gravity = GRV_OB and x.table_no = tble) order by tble, tempr, grv_ob
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.