Hi,
Try this:
IF @transaction_type IN (N'A', N'U') AND
(@Object_type = N'15')
begin
if exists (SELECT T0.BaseEntry, SUM(T0.Quantity)
FROM dbo.DLN1 T0 INNER
JOIN dbo.INV1 T1 ON T1.DOCENTRY =
T0.BASEENTRY inner join dbo.OINV T2 on T2.docentry = T1.docentry
WHERE T0.BaseType = 17 AND T0.ItemCode =
T1.ItemCode AND T0.BaseLine = T1.LineNum and T2.[isIns] = 'y'
and T0.DOCENTRY = @list_of_cols_val_tab_del
GROUP BY T0.BaseEntry
HAVING (SUM(T0.Quantity) > SUM(T1.Quantity)) or sum(t0.quantity) >
sum(t0.BaseOpnQty))
begin
select @Error = 10, @error_message = 'Delivery quantity is greater than Reserve qty.'
Thanks