on 10-02-2019 10:44 AM
Buen día estimados,
Estoy tratando de hacer una validación para que no me permita generar una orden de venta si la utilidad es menor al 10%, tengo una consulta la cual solo valida cuando es una sola linea y yo necesito que lo haga pero n cantidad de lineas, siguiente
IF @object_type = '17' AND @transaction_type IN('U','A')
BEGIN
IF (SELECT (T1.[Price]- T2.[AvgPrice])/T1.[Price]*100 FROM ORDR T0 INNER JOIN RDR1 T1 ON T0.[DocEntry] = T1.[DocEntry]
INNER JOIN OITM T2 ON T1.[ItemCode] = T2.[ItemCode] WHERE T0.[DocNum] =@list_of_cols_val_tab_del)<'10'
--AND T1.LineNum = @num_of_cols_in_key
BEGIN
Set @error = -1011
Set @error_message = 'Utilidad menor al 10%'
END
END
Gracias a todos por sus respuestas, la solución que dio Aziz me funciono muy bien
Saludos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hola Diego,
No soy bueno en español, Pero, permítanme compartir con ustedes la siguiente solución:
IF @object_type = '17' AND @transaction_type IN('U','A')
BEGIN
IF EXISTS (SELECT T0.Docnum,T1.LineNum ,T1.ItemCode,T1.Quantity,T1.[Price],T2.[AvgPrice] FROM ORDR T0 INNER JOIN RDR1 T1 ON T0.[DocEntry] = T1.[DocEntry] INNER JOIN OITM T2 ON T1.[ItemCode] = T2.[ItemCode]
WHERE (T1.[Price]- T2.[AvgPrice])/T1.[Price]*100 < 10 AND T0.[DocNum] =@list_of_cols_val_tab_del)
BEGIN
Set @error = -1011
Set @error_message = 'Utilidad menor al 10%'
END
END
Espero que esto te ayude!
Aziz
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hola
si lo que quieres es validar que todas las líneas tengan una utilidad mayor del 10%, debes verificar línea por línea del documento, y no puedes hacer un inner join porque esta consulta devolverá verdadero cuando encuentre una línea que lo cumpla.
La solución pasa por utilizar un cursor para recorrer todas las líneas del documento, y si todas cumplen la condición mostrar el mensaje.
Un saludo
Agustín
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
106 | |
12 | |
10 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.