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 |
|
abc123
Starting Member
47 Posts |
Posted - 2009-03-04 : 01:43:11
|
| I have 3 tables as followtab1ID CurrentUSer1 XYZ2 NULL3 XYZ 4 PQR5 NULLtb2ID IDStatus1 Close2 pending3 approve4 reject5 inqueuetb3UID Uname Rid1 ABC 12 PQR 23 XYZ 3I want to update tb1.CurrentUSer according to different tb2.IDStatus with different tb3.Uname ex- 1. if tb2.IDStatus = pending then update tb1.CurrentUSer = 'ABC' where tb3.Rid = 1 2. if tb2.IDStatus = reject then update tb1.CurrentUSer = 'XYZ' where tb3.Rid = 3 3. if tb2.IDStatus = Close then update tb1.CurrentUSer = NULL please tell me how i can update tb1.CurrentUSer column for different condition |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-04 : 08:47:17
|
use a case expressionUPDATE t1SET t1.CurrentUser=CASE WHEN t2.IDStatus='pending' AND t3.Rid=1 THEN 'ABC' WHEN t2.IDStatus='reject' AND t3.Rid=3 THEN 'XYZ' WHEN t2.IDStatus='Close' THEN NULL ENDFROM tab1 t1JOIN tb2 t2ON t1.ID=t2.IDJOIN tb3 t3ON t3.UID=t1.ID |
 |
|
|
|
|
|