I am working with Wisys Agility Design Studio and writing SQL statements to determine sales differences from year to year.
Case where I determine the 2016 sales data
CASE
WHEN oehdrhst_wv.inv_dt LIKE '%2016%' THEN ( oelinhst_wv.qty_to_ship - oelinhst_wv.qty_return_to_stk ) * oelinhst_wv.unit_price * ( 1 - oelinhst_wv.discount_pct / 100 )
END AS '2016 Sales',
Case where I determine YTD 2015 comparable to 2016 data
CASE
WHEN oehdrhst_wv.inv_dt BETWEEN '1/1/2015' AND Dateadd(Year, -1, Getdate()) THEN ( oelinhst_wv.qty_to_ship - oelinhst_wv.qty_return_to_stk ) * oelinhst_wv.unit_price * ( 1 - oelinhst_wv.discount_pct / 100 )
END AS 'YTD 2015 Sales',
I then created the case to determine the difference between the two
CASE
WHEN oehdrhst_wv.inv_dt BETWEEN '1/1/2015' AND Dateadd(Year, -1, Getdate()) THEN -( ( oelinhst_wv.qty_to_ship - oelinhst_wv.qty_return_to_stk ) * oelinhst_wv.unit_price * ( 1 - oelinhst_wv.discount_pct / 100 ) )
WHEN oehdrhst_wv.inv_dt LIKE '%2016%' THEN ( ( oelinhst_wv.qty_to_ship - oelinhst_wv.qty_return_to_stk ) * oelinhst_wv.unit_price * ( 1 - oelinhst_wv.discount_pct / 100 ) )
END AS 'YTD Diff',
I now what to create the Percentage Difference for the two, and this is where I am stuck. I cannot divide a Case by a Case. Help
Case where I determine the 2016 sales data
CASE
WHEN oehdrhst_wv.inv_dt LIKE '%2016%' THEN ( oelinhst_wv.qty_to_ship - oelinhst_wv.qty_return_to_stk ) * oelinhst_wv.unit_price * ( 1 - oelinhst_wv.discount_pct / 100 )
END AS '2016 Sales',
Case where I determine YTD 2015 comparable to 2016 data
CASE
WHEN oehdrhst_wv.inv_dt BETWEEN '1/1/2015' AND Dateadd(Year, -1, Getdate()) THEN ( oelinhst_wv.qty_to_ship - oelinhst_wv.qty_return_to_stk ) * oelinhst_wv.unit_price * ( 1 - oelinhst_wv.discount_pct / 100 )
END AS 'YTD 2015 Sales',
I then created the case to determine the difference between the two
CASE
WHEN oehdrhst_wv.inv_dt BETWEEN '1/1/2015' AND Dateadd(Year, -1, Getdate()) THEN -( ( oelinhst_wv.qty_to_ship - oelinhst_wv.qty_return_to_stk ) * oelinhst_wv.unit_price * ( 1 - oelinhst_wv.discount_pct / 100 ) )
WHEN oehdrhst_wv.inv_dt LIKE '%2016%' THEN ( ( oelinhst_wv.qty_to_ship - oelinhst_wv.qty_return_to_stk ) * oelinhst_wv.unit_price * ( 1 - oelinhst_wv.discount_pct / 100 ) )
END AS 'YTD Diff',
I now what to create the Percentage Difference for the two, and this is where I am stuck. I cannot divide a Case by a Case. Help