Buen día, necesito hacer un bloqueo para la solicitud de compra en donde no puede exceder el 18% de las ventas en la última semana, he probado lo siguiente pero no me funciona, les agradezco su aporte.
IF @object_type =1470000113 AND @transaction_type IN ('A')
BEGIN
IF EXISTS
((select T0.[DocTotal] from
OPRQ T0
INNER JOIN PRQ1 T1 ON T0.[DocEntry] = T1.[DocEntry]
where T0.[DocEntry] = CAST(@list_of_cols_val_tab_del AS NVARCHAR(15))
AND T1.[WhsCode]= '00' AND T0.[UserSign]<> '1' AND T0.[DocTotal]>
((SELECT sum(ISNULL(T0.[DocTotal],0))
FROM OINV T0
INNER JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry]
WHERE T1.[WhsCode]= '00' and T0.[DocDate] >= DATEADD(dd,-8, CONVERT(DATE,GETDATE())
) and T0.[DocDate] <= DATEADD(dd,-1,GETDATE())
-
(SELECT sum(ISNULL(T0.[DocTotal],0))
FROM ORIN T0
INNER JOIN RIN1 T1 ON T0.[DocEntry] = T1.[DocEntry]
WHERE T1.[WhsCode]= '00' and T0.[DocDate] >= DATEADD(dd,-8, CONVERT(DATE,GETDATE())
) and T0.[DocDate] <= DATEADD(dd,-1,GETDATE()))
))*0.18))
Begin
set @error = 9
set @error_message = 'Excede el presupuesto'
End
End