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
Windows 2008 ServeRaid driver
Follow up php question - php mailer
Service policy is in suspended mode
SQL AFTER UPDATE TRIGGER
"INACCURATE FILE WAS SPECIFIED"
HP PRINTER P3015 and P3005 cartridge compartible?
Does anyone know how to make a disk image from the iphone memory?
varchar column1 sort, want to add 'hello'
Restore from older backups
phpbb forum