Question: In the code below i have two microsoft sql server queries included in a stored procedure, the first query is executing like a charm but the second query never get executed , i make sure that both table have data inside and matches the condition i put ,the code is executing and returning success 

```
create procedure sp_ProcApps
@Cheque cheque readonly,
@Advances advance readonly
as     
begin transaction 
begin try

MERGE INTO apps_ AS application
USING @Cheque c ON application.appid= c.appid 

WHEN MATCHED THEN
UPDATE 
SET  application.Reaudit=0,application.Id = c.id,application.status=6,application.closed=1;

MERGE INTO apps_ AS application1
USING @Advances adv ON application1.appid= adv.appid 

WHEN MATCHED THEN
UPDATE 
SET  application1.reaudit=0,application1.status=6,application1.closed=1,application1.Id =14  ;

SELECT @IsOK='s'
COMMIT;
end TRY
BEGIN CATCH
SELECT @IsOK='f'
ROLLBACK;
END CATCH

```

Answer: 
I wouldn't use MERGE for just an update. The MERGE statement has some issues (<https://www.mssqltips.com/sqlservertip/3074/use-caution-with-sql-servers-merge-statement/>) and really isn't needed here. Using joins this is a lot simpler.

```
UPDATE a
SET Reaudit = 0
    , Id = c.id
    , status = 6
    , closed = 1
from apps a
join @Cheque c on c.appid = a.appid

UPDATE a
SET reaudit = 0
    , status = 6
    , closed = 1
    , Id =14
from apps_ AS a
join @Advances adv ON a.appid= adv.appid

```
Finally i am able to find the error that the second defined table type has reversed order between AppId and Id column ,though they have the same names on c# snippet that send the params to sql , i reordered the column on sql defined table type as they are sent from c# data table and i have it worked, and the above answer is a simple anwwer two