Forum Discussion

Paul Critchley's avatar
Paul Critchley
Copper Contributor
Aug 09, 2018

Hi, is it possible to calculate a field that has already been calculated in a query

I can do this in excel but want to code it automatically

 

The below code works fine in but i want to calculate 'YTD Scrap' / 'YTD Issues'

SELECT stockm.warehouse, stockm.product, stockm.long_description, stockm.analysis_a, stockm.analysis_b, (stockm.year_to_date02-stockm.year_to_date09) AS 'YTD Issues', stockm.year_to_date06 AS 'YTD Scrap'
FROM live.scheme.stockm stockm
WHERE (stockm.year_to_date06>0) AND (stockm.year_to_date02>0)
ORDER BY stockm.product

  • Philip West's avatar
    Philip West
    Steel Contributor

    Can you not perform the maths in the query?

     

    SELECT stockm.warehouse, stockm.product, stockm.long_description, stockm.analysis_a, stockm.analysis_b, (stockm.year_to_date02-stockm.year_to_date09) AS 'YTD Issues', stockm.year_to_date06 AS 'YTD Scrap', ('YTD Scrap' / 'YTD Issues') AS 'YTD Calculated'
    FROM live.scheme.stockm stockm
    WHERE (stockm.year_to_date06>0) AND (stockm.year_to_date02>0)
    ORDER BY stockm.product

Resources