Microsoft
Software
Hardware
Network
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.
PRODUCTTYP
E, 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.
STKHEADCOD
E = ACOCMP1.STKHEADINFO.STKCOD
E ON
ACOCMP1.CURRSALE.STKCODE = ACOCMP1.STKHEADINFO.STKCOD
E
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
PL/SQL Performance
Trying to redirect a user from http to https automatically. Windows 2008 running II7
How to commit changes of a Typed Dataset to database at once
SQL 2005 Query Help
java.lang.UnsatisfiedLinkE
rror
having trouble connecting workstations to new SBS 2008
Move DC role from Exchange Server
Read Outlook End User email from Exchange Server 2007
How Can I Get Rsync to Include Subdirectories?
can ping by ip, and by name, but not browse