Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

issue with merge in output when update

$
0
0

Problem - I put everything in a store procedure.Initially source.efforts=10. When I execute 1st time it is working fine.

  • Later when I updated source.efforts=15 and ran stored procedure update not working. I cannot see update value changed in table3 target table values also not updated correctly.
  • when i execute same stored procedure then am getting right value.I'm not able to figure it out.
  • When I comment bold lines then it is working but i want capture the conditions.

MERGE table1 AS target
USING (
    SELECT a.aid,a.efforts,ab.lcs
    FROM cip a
    INNER JOIN dc ab ON a id = ab.id
    WHERE a.id = @id
    ) AS source
    ON ( target.caseid = @caseidupd
            AND target.aid = source.aid
            )
WHEN MATCHED AND source.lc IN (1,2)
    THEN
        UPDATE
        SET target curr = CASE
                WHEN source.efforts = 0
                    THEN source.efforts source.efforts <> 0 then source.efforts
                END
    SET target tar= CASE
                WHEN source.efforts = 0
                    THEN source.efforts source.efforts <> 0 then target.curr
                END
            ,target.modi = CASE
                WHEN source.efforts = 0
                    THEN getdate() source.efforts <> 0 then getdate()
                END
WHEN NOT MATCHED BY target
    THEN
        INSERT (caseid,aid,modi)
        VALUES (@caseidupd,source.aid,getdate())
output $action
case
when $action='INSERT' THEN 'APPINSERT'
case when $action='UPDATE' THEN 'APPzeroed'
case when $action='UPDATE' THEN 'source value' +curr +'changed to'+tar

INTO table3





Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>