I'm trying to figure out why this query SELECTs just fine, but I can't use it to create a temporary table... The IF = '', 0
stuff didn't used to exist in the original query so I added it to make sure that I wasn't trying to sum anything that could potentially be an empty string, but it didn't fix the problem. This select works and returns the correct result set:
SELECT
SUM(((IF(reserve_transactions.Revenue = '',
0,
reserve_transactions.Revenue) * IF(reserve_transactions.Confidence = '',
0,
reserve_transactions.Confidence)) / 100)) AS rawadjusted
FROM
(store_locations
LEFT JOIN reserve_transactions ON ((store_locations.ID = location_sales)))
GROUP BY store_locations.Loc_Long
But this does not:
CREATE TEMPORARY TABLE tmptable_which_doesnt_work AS SELECT
SUM(((IF(reserve_transactions.Revenue = '',
0,
reserve_transactions.Revenue) * IF(reserve_transactions.Confidence = '',
0,
reserve_transactions.Confidence)) / 100)) AS rawadjusted
FROM
(store_locations
LEFT JOIN reserve_transactions ON ((store_locations.ID = location_sales)))
GROUP BY store_locations.Loc_Long
The error is: Error Code: 1292. Truncated incorrect DECIMAL value: ''
I have other queries where the situation is the same, actually. Sometimes with other truncated incorrect types. What am I missing here?