| Author |
Topic |
|
Sonu619
Posting Yak Master
202 Posts |
Posted - 2011-04-14 : 20:52:55
|
| Hi guys, I am in trouble need help, I have two table TABLE A and Table BTable A hasID,FNAME,R_ID1,MIKE,252,JAMES,451,SMITH,26TABLE B hasID,CITY,R_ID1,CA,NULL2,MA,NULL1,NY,NULLI want to Populate Table B.R_ID from Table A.R_ID i am using update statementUPDATE TABLE BSET R_ID = TABLE A.R_IDFROM TABLE BINNER JOIN TABLE AON TABLE A.ID = TABLE B.IDHere is the result i am gettingTABLE BID,CITY,R_ID1,CA,252,MA,451,NY,25I want result like this TABLE BID,CITY,R_ID1,CA,252,MA,451,NY,26SO i tried everything to fix this issue but i couldn't achieve, here i have solution but i need your help. I have to add one column in Table A and Add one more column in Table Bbut my question is how i give a value to TABLE A.ID, 1 SAME to TABLE B.ID ?so then i can use this update statement. UPDATE TABLE BSET R_ID = TABLE A.R_IDFROM TABLE BINNER JOIN TABLE AON TABLE A.ID = TABLE B.IDand TABLE A.TEST = TABLE B.TESTIf someone know better way to do this please feel free to let me know. If any one need more info or my question is not clear i can give you more information. Thanks. |
|
|
lappin
Posting Yak Master
182 Posts |
Posted - 2011-04-15 : 11:19:36
|
| Your code looks right to me. I use this as general template:UPDATE t2SET Fld2 = t1.Fld2 FROM Table2 t2INNER JOIN Table1 t1ON t2.Fld1 = t1.Fld1 |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-04-15 : 12:16:05
|
| How do you match 1,MIKE,25 to 1,CA,NULL and not 1,NY,NULLDoesn't look to be anything here to join on (which is the problem you are finding).What you are requesting can't be done with your current data.You can take the IDs from both tables and when they are the same match on the order of the name and city (alphabetically) but I suspect that's not what you want.==========================================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. |
 |
|
|
Sonu619
Posting Yak Master
202 Posts |
Posted - 2011-04-18 : 19:08:55
|
| Table A hasID,FNAME,R_ID1,MIKE,252,JAMES,451,SMITH,26TABLE B hasID,CITY,R_ID1,CA,NULL2,MA,NULL1,NY,NULLwhat i am trying to do to populate TABLE B.R_ID FROM TABLE A.R_ID and ID is the link. Code is fine no problem but the problem is duplicate ID, that's why they giving me Duplicate R_ID. Please let me know if you need more explanation. Thanks. |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2011-04-18 : 19:26:09
|
| sounds more like homework than real life. either way the only way you can do it is manual because as nigelrivett there is nothing to join on.If you don't have the passion to help people, you have no passion |
 |
|
|
|
|
|