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 |
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2008-07-11 : 11:43:29
|
| I have two tables. AROPNFILARSLMFILThey both have the field slspsn_no.The AROPNFIL has values in the slspn_no field that do not exist in theARSLMFIL.What I would like to do is change the value to '001' if the currentvalue in the AROPNFIL does not exist in the ARSLMFIL. |
|
|
cvipin
Yak Posting Veteran
51 Posts |
Posted - 2008-07-11 : 11:53:07
|
| update AROPNFILset slspn_no = '001'where NOT EXISTS(SELECT 1 FROM ARSLMFIL WHERE AROPNFIL.slspn_no = ARSLMFIL.slspn_no) |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-07-11 : 12:02:59
|
| try thisDeclare @a table ( sometext varchar(50))insert into @a select 'system' union allselect 'communication' union allselect 'electronics'select * from @aDeclare @b table ( sometext varchar(50))insert into @b select 'system' union allselect 'sierra' union allselect 'tata'select * from @bupdate a1set sometext = '001'from @a a1 left join @b b1 on (a1.sometext = b1.sometext )where b1.sometext is nullselect * from @a |
 |
|
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2008-07-11 : 12:27:53
|
| The first suggestion worked perfectly. thanks alot |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-07-11 : 12:34:34
|
| If you want a straight forward answer then try thisUPDATE ASET A.slspn_no = '001'FROM AROPNFIL ALEFT JOIN ARSLMFIL AR ON ( AR.slspn_no = A.slspn_no )WHERE AR.slspn_no IS NULL |
 |
|
|
|
|
|