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
problem exportting gridview to excel spreadsheet
Will there be a 13" Macbook with an iCore processor anytime soon? Safe to buy C2D?
Problems Replicating SYSVOL and NETLOGON on new DC WS 2008 R2 Standard in 2003 AD
JavaScript Error in IE7 menu hover background does not work
do i need licenses per user if i buy exchange server?
Clearing a submit form once submitted
Stringtopostnet function not working in Crystal viewer 2008 ---
Possible Virus Infection - Can not connect to Internet, Max TCP connections reached.
How to use DriverGeek to restore drivers
In Latex, how do I change the format of automatic equation numbering?