This is HDBC and Sqlite3. It says there's a syntax error near "CASE". But I can'd find such. Is there any ?
calculateNoOfStocksTraded::String->Database.HDBC.Sqlite3.Connection->IO () calculateNoOfStocksTraded code conn=do
run conn " CREATE TRIGGER calcStocks \
\ AFTER INSERT ON historicalData \
\ FOR EACH ROW \
\ BEGIN \
\ CASE WHEN (SELECT COUNT(*) FROM historicalData) >= 1 THEN \
\ UPDATE company \
\ SET noOfStocks=(SELECT SUM(volume) FROM historicalData WHERE companyCode= ? ) \
\ WHERE code= ? ; \
\ ELSE \
\ UPDATE company \
\ SET noOfStocks=0 \
\ WHERE code= ? ; \
\ END \
\ END; " [toSql code,toSql code, toSql code]
commit conn