Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

INSERT INTO tbl_WMSDeviationPenality (

SessionID,
AgencyID,
MandiID,
WarehouseID,
ExitPassId,
PenalityType,
DeviationType,
ArthiyaId_TransporterId,
MoisterParm,
DeviationOn,
No_of_Bags,
Deviation,
LusterLoss,
ShriveledLoss,
Remarks,
CreatedDate,
CreatedUser,
RemovePenalityDate,
RemoveStatus,
RemovePenalityUser
)
SELECT
e.SessionID,
e.AgencyID,
max(w.mandiid),
e.WarehouseID,
e.eGatePassID,
'A', -- Replace NULL with the appropriate value or field if available
'10', -- Replace NULL with the appropriate value or field if available
max(gpd.ArthiyaID), -- Replace NULL with the appropriate value or field if
available
'1', -- Replace NULL with the appropriate value or field if available
CASE
WHEN e.NoofBags < e.Exitgatepassbags AND e.BagsNetWeight <
e.ExitGatePassWeight THEN 'D'
WHEN e.NoofBags < e.Exitgatepassbags AND e.BagsNetWeight =
e.ExitGatePassWeight THEN 'B'
WHEN e.BagsNetWeight < e.ExitGatePassWeight AND e.ExitGatePassBags =
e.NoOfBags THEN 'W'
END, -- Replace NULL with the appropriate value or field if available
e.ExitGatePassBags-e.NoofBags,
e.ExitGatePassWeight-e.BagsNetWeight, -- Replace NULL with the appropriate
value or field if available
0, -- Replace NULL with the appropriate value or field if available
0, -- Replace NULL with the appropriate value or field if available
NULL,
e.CreatedDate, -- Assuming current date is required
e.CreatedUser,
NULL, -- Replace NULL with the appropriate value or field if available
NULL, -- Replace NULL with the appropriate value or field if available
NULL -- Replace NULL with the appropriate value or field if available
FROM tbl_WMSINWardStack e
INNER JOIN tbl_WMSGatePass w ON e.eGatePassID = w.eGatePassID
inner join tbl_WMSGatePassDetails gpd on e.eGatePassID =gpd.egatePassID
WHERE e.NoofBags < e.Exitgatepassbags
or e.BagsNetWeight < e.ExitGatePassWeight
AND e.[Status] IS NULL
AND e.Remarks IS NULL
group by e.SessionID,
e.AgencyID,
e.WarehouseID,
e.eGatePassID,
e.CreatedDate, -- Assuming current date is required
e.CreatedUser ,
e.BagsNetWeight,
e.NoofBags,
e.ExitGatePassBags,
e.ExitGatePassWeight

can have three cases < = and 0 so modify accordingly

You might also like