- I have below oracle query need to converted to ms sql. I also want to add a record into journal table when a
Update table1 target
set curr =
decode(
(
select efforts from (
select source.efforts efforts
from
(
SELECT a.aid,a.efforts,ab.lcs
FROM CIP a, DC ab
WHERE a id = ab.id
AND a.id = @id
) source
where target.caseid = @caseidupd
and target.aid = source.aid
) tmp, 0, tmp.efforts, curr
),
modi = getdate( )
where exists
(
select 1
from table1 tgt
where tgt.aid = target.aid
and tgt.caseid = @caseidupd
);
insert into table1 values(caseid, aid, modi)
select @caseidupd, source.aid, getdate()
from
(
SELECT a.aid,a.efforts,ab.lcs
FROM CIP a, DC ab
WHERE a id = ab.id
AND a.id = @id
) source
where not exists
(
select 1
from table1 target
where target.aid = source.aid
and target.caseid = @caseidupd
);
something like this...
INSERT (caseid,aid,modi)
select @caseidupd,'appupdated'+source.aid,getdate()
INSERT (caseid,aid,modi)
select (@caseidupd,'appinserted'+source.aid,getdate()