0% found this document useful (0 votes)
20 views2 pages

Consult As

The document contains SQL statements that update cost values for invoice line items based on account numbers, and calculates profit percentages and updates costs to achieve a target profit range.

Uploaded by

Camilo Paz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Consult As

The document contains SQL statements that update cost values for invoice line items based on account numbers, and calculates profit percentages and updates costs to achieve a target profit range.

Uploaded by

Camilo Paz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

-- 21.

-- actualizacion de utilidad
update InvoiceLineItems
set InvoiceLineCost=InvoiceLineItemAmount/1.20
Where AccountNo between 150 and 170

update InvoiceLineItems
set InvoiceLineCost=InvoiceLineItemAmount/1.25
Where AccountNo between 400 and 507

update InvoiceLineItems
set InvoiceLineCost=InvoiceLineItemAmount/1.35
Where AccountNo > 507

-- 21. -- revisar utilidad


with CTE_UTILIDAD
AS
(
select InvoiceID AS NFACTURA,
AccountNo AS COD_PROD,
InvoiceLineItemDescription AS PRODUCTO,
InvoiceLineItemAmount AS TOTAL_VENTAS,
InvoiceLineCost AS TOTAL_COSTOS
from InvoiceLineItems
)
select *,
TOTAL_VENTAS-TOTAL_COSTOS AS UTILIDAD
ROUND ((TOTAL_VENTAS-TOTAL_COSTOS)/TOTAL_VENTAS * 100,2) as P_UTILIDAD
FROM CTE_UTILIDAD

-- 22. -- revisar utilidad


with CTE_UTILIDAD
AS
(
select InvoiceID AS NFACTURA,
AccountNo AS COD_PROD,
InvoiceLineItemDescription AS PRODUCTO,
InvoiceLineItemAmount AS TOTAL_VENTAS,
InvoiceLineCost AS TOTAL_COSTOS
from InvoiceLineItems
)
select distinct ROUND ((TOTAL_VENTAS-TOTAL_COSTOS)/TOTAL_VENTAS * 100,2) as
P_UTILIDAD
FROM CTE_UTILIDAD
order by P_UTILIDAD desc

-- 22. ---

with CTE_UTILIDAD
AS
(
select InvoiceID AS NFACTURA,
AccountNo AS COD_PROD,
InvoiceLineItemDescription AS PRODUCTO,
InvoiceLineItemAmount AS TOTAL_VENTAS,
InvoiceLineCost AS TOTAL_COSTOS
from InvoiceLineItems
)
UPDATE InvoiceLineItems
Set InvoiceLineCost=U.TOTAL_VENTAS / (1+ (((20-
ROUND ((U.TOTAL_VENTAS-U.TOTAL_COSTOS)/
U.TOTAL_VENTAS *100,2)) +
ROUND ((U.TOTAL_VENTAS-U.TOTAL_COSTOS)/
U.TOTAL_VENTAS *100,2)) /100),
FROM CTE_UTILIDAD U inner join InvoiceLineItems D
on U.FACTURA = D.InvoiceID
and U.COD_PROD=D.AccountNo
Where ROUND ((U.TOTAL_VENTAS-U.TOTAL_COSTOS)
/U.TOTAL_VENTAS * 100,2)
between 0 and 16.67

You might also like