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
How to change Hotsname and ipaddress of Oracle Databse server
Migration from 2003 SBS to 2008 Foundation Server
IOS VPN Configuration for iPhone
How do I fix odbc call failed #1062 under access vba with a mysql backend?
Windows Server 2008 NLB Issue
quick question
Exchange 2010 Tarpit issue
How can I compare Files in a Directory with a Text File List using a DOS Batch File?
Union query
SQLservr.exe*32 process using large amount of ram and disk activity