I keep receiving this error Column 'vStockSerialsTemp.Id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. ALTER VIEW vStockSerials as
SELECT Id
, StockOid
, WarehouseOid
, serial
, StockCode
, ActionPrice
, StockName
, StockTitle
, Warehouse
, SlipDate
, ActionType
, SlipType
FROM vStockSerialsTemp
UNION ALL
SELECT Id
, StockOid
, WarehouseOid
, serial
, StockCode
, sum(CASE WHEN ActionType = 'Income' THEN ActionPrice ELSE -ActionPrice END) as ActionPrice
, StockName
, StockTitle
, Warehouse
, SlipDate
, SlipType
, 'Balance' as ActionType
FROM vStockSerialsTemp
GROUP BY
serial
HAVING sum(CASE WHEN ActionType = 'Expense' THEN ActionPrice ELSE -ActionPrice END) <> 0
--ORDER BY
-- ActionType DESC
GO