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.
| Author |
Topic |
|
SHIVPREET2K1
Starting Member
32 Posts |
Posted - 2010-05-26 : 06:15:36
|
Dear Friends I have one table in which i have this dataA_R5Item_Code sub_item_code1 Sub_item_code2 Sub_item_code3A B C X Y CI execute this queryinsert into A_R5(Sub_item_code2,Sub_item_code3) select item_code,rm_code from rm_mc_polish_Cost_of_items where item_code in (Select sub_item_code2 from A_R5)I got following outputA_R5Item_Code sub_item_code1 Sub_item_code2 Sub_item_code3A B C X Y CX Y C D In the rm_mc_polish_cost_of_items is sub_item_code3 is place which is related with sub_item_code2 onlyMy question is why this query is inserting the new record for second row only (with X item) and why not for first record (A item)RM_Mc_polish_cost_of_item has only relation with sub_item_code2that is with (C Item)Please tell me where I am wrong in this query. thanks in advanceShivpreet2k1 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-26 : 07:14:02
|
My questions are:Your posted code is inserting values only for Sub_item_code2,Sub_item_code3 so how can it be that after your insert the columns Item_Code and sub_item_code1 are filled with X and Y?Whre is the example data for table rm_mc_polish_Cost_of_items? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
SHIVPREET2K1
Starting Member
32 Posts |
Posted - 2010-05-26 : 07:54:11
|
thnaks for your query buddythis is my logic for for inserting the item_code and sub_item_code1update aset a.Sub_item_code2=b.Sub_item_Code2 from A_R5 ainner join A_R5 b on a.sub_item_code3=b.sub_item_code3where a.Sub_item_code2 is null and b.sub_item_code2 is not nullupdate aset a.Sub_item_code1=b.Sub_item_Code1 from A_R5 ainner join A_R5 b on a.sub_item_code2=b.sub_item_code2where a.Sub_item_code1 is null and b.sub_item_code1 is not nullupdate aset a.item_code=b.item_code from A_R5 ainner join A_R5 b on a.sub_item_code1=b.sub_item_code1where a.item_code is null and b.item_code is not null Thanks for ur query |
 |
|
|
|
|
|