I want to use two trigger on Update in #tbl_BalPacM table,First if Column Orderno Update then below trigger Execute
ALTER trigger [dbo].[mytriggerorderno] on [dbo].[tbl_BalPacM]
after update
as
begin
if update (orderno)
begin
update a
set a.orderno=b.orderno
from tbl_PckDetail a
inner join inserted b
on a.pid=b.pid
where a.DelID is null
update a
set a.orderno=b.orderno
from Probale a
inner join tbl_PckDetail b
on a.prdno=b.prdno
inner join inserted c
on c.pid=b.pid
where a.DelID is null and b.DelID is null
end
end
Second Trigger IF #tbl_BalPacM Column(del) Update with 1 then execute below code,(Note : Below Trigger is not working ,means that when i execute it,then table #tbl_PckDetail delid and table #probale column PID updated with 1.
ALTER trigger [dbo].[mytriggerdel] on [dbo].[tbl_BalPacM]
after update
as
begin
if update (delid)
begin
update a
set a.orderno=b.orderno
from tbl_PckDetail a
inner join inserted b
on a.pid=b.pid
-- where a.DelID is null
update a
set a.orderno=b.orderno
from Probale a
inner join tbl_PckDetail b
on a.prdno=b.prdno
inner join inserted c
on c.pid=b.pid
-- where b.DelID is null
end
end
Here is my data,
Create Table #itemmasterfile(CodeItem int,CID int,Descriptionitem varchar(50),Packsize varchar(50))
CREATE TABLE #Probale (prdno INT,orderno int,CodeItem int,Weigth int,prdqty int,EntryDate date,DelID int,PID int)
Create table #tbl_BalPacM (PID int ,Orderno int,del int)
Create table #tbl_PckDetail (DID int,PID int,Orderno int, prdno int,delid int)
INSERT INTO #Probale VALUES(10000,15,1,270,1,'2020-10-21',null,111)
INSERT INTO #Probale VALUES(10001,15,2,270,1,'2020-10-21',null,111)
INSERT INTO #Probale VALUES(10002,15,3,270,1,'2020-10-21',null,111)
INSERT INTO #Probale VALUES(10003,15,4,270,1,'2020-10-21',null,111)
INSERT INTO #Probale VALUES(10004,16,5,270,1,'2020-10-21',null,112)
INSERT INTO #Probale VALUES(10005,16,6,270,1,'2020-10-21',null,112)
Insert into #tbl_BalPacM values (111,15,null)
insert into #tbl_PckDetail values(101,111,15,10000,null)
insert into #tbl_PckDetail values(101,111,15,10002,null)
insert into #tbl_PckDetail values(101,111,15,10003,null)
insert into #tbl_PckDetail values(101,111,15,10004,null)