Problem :

Table1

```
CatId - -   Type - -    Qty
==============================
8        ||    O   ||   10
8        ||    N   ||   20
8        ||    U   ||   30
30       ||    N   ||   5
30       ||    O   ||   15
30       || NULL   ||   25

```

---

Table2

```
catId -- Old -    -New -- Useless -- Other
========================================
8      || 100   || 70   ||  140      || 110
30     || 10    || 20   ||  30       || 50

```

---

Result: Update Table 2 with Table 1 Like

```
-------------------------------------------------
catId --   Old --   New -- Useless -- Other
8       || 90    || 50  ||  110     || 110
30      ||  5    ||  5  ||  30      || 25

```

How result should come : 

Table 1 and Table 2 has a common column CatId.

```
Column of table 1 Type is connects with Table2  
    AS  (Old - O / New - N / Useless - U / Other - NULL)

```

I want subtract Like table2(Respective O/N/U/Other) = table2(Respective O/N/U/Other) - table1(Type) and would prefer solution without loop

I tried this but not working Properly --

```
Update Table2
Set New = New - (CASE Type WHEN 'N' THEN (Table1.qty) Else 0 End),
    Old = Old  - (CASE Type WHEN 'O' THEN (Table1.qty) Else 0 End),
    Old = Old  - (CASE Type WHEN 'O' THEN (Table1.qty) Else 0 End),
    Other= Othere- (CASE Type WHEN is Null THEN (Table1.qty) Else 0 End)
from table1 
inner join table2 
On table1.catId = table2 .catId

```