Question : SQL Query calculation in a View

Hi,
I have an sql view and in that view i have sales figures for products.

I want to add a column so that i can display the profit for each row in a column named profit.

the profit would be (ACOCMP1.CURRSALE.AMOUNT - ACOCMP1.CURRSALE.COST)

My current view query is this:

SELECT     TOP (100) PERCENT ACOCMP1.CURRSALE.TRANDATE, ACOCMP1.CURRSALE.STKCODE, ACOCMP1.CURRSALE.STKTYPE, ACOCMP1.CURRSALE.QTY,
                      ACOCMP1.CURRSALE.COST, ACOCMP1.CURRSALE.AMOUNT, ACOCMP1.CURRSALE.CUSAC, ACOCMP1.CURRSALE.SESSREF, ACOCMP1.CURRSALE.DEPNO,
                      ACOCMP1.CURRSALE.CCNO, ACOCMP1.CURRSALE.SALESMAN, ACOCMP1.CURRSALE.COUNTRY, ACOCMP1.CURRSALE.NOMAC, ACOCMP1.CURRSALE.INVNO,
                      ACOCMP1.STKCATALOGENTRIES.PRODUCTTYPE, ACOCMP1.STKCATALOGENTRIES.SUPP1, ACOCMP1.STKCATALOGENTRIES.MANCODE,
                      ACOCMP1.STKCATALOGENTRIES.STKCAT, ACOCMP1.SALESTAF.SURNAME, ACOCMP1.SALESTAF.FORENAMES, ACOCMP1.STKHEADINFO.DES1,
                      ACOCMP1.DSINVTRN.DES
FROM         ACOCMP1.CURRSALE LEFT OUTER JOIN
                      ACOCMP1.DSINVTRN ON ACOCMP1.CURRSALE.ITEMREF = ACOCMP1.DSINVTRN.ITEMREF LEFT OUTER JOIN
                      ACOCMP1.SALESTAF ON ACOCMP1.CURRSALE.SALESMAN = ACOCMP1.SALESTAF.WRKNUM LEFT OUTER JOIN
                      ACOCMP1.STKCATALOGENTRIES INNER JOIN
                      ACOCMP1.STKHEADINFO ON ACOCMP1.STKCATALOGENTRIES.STKHEADCODE = ACOCMP1.STKHEADINFO.STKCODE ON
                      ACOCMP1.CURRSALE.STKCODE = ACOCMP1.STKHEADINFO.STKCODE
ORDER BY ACOCMP1.CURRSALE.ITEMREF

How can i alter the query above to display the profit column ?
Many Thanks.

Answer : SQL Query calculation in a View

add this just before the from clause.  ,(ACOCMP1.CURRSALE.AMOUNT - ACOCMP1.CURRSALE.COST) as Profit
Random Solutions  
 
programming4us programming4us