On 2016/03/04 4:29 PM, Paul van Helden wrote:
> On Fri, Mar 4, 2016 at 4:23 PM, Igor Tandetnik <igor at tandetnik.org> wrote:
>
>> On 3/4/2016 9:15 AM, Paul van Helden wrote:
>>
>>> So I have to detect integers in order to avoid the .0
>>>
>> WHERE CAST(A as integer) = 1
>>
>>
> Not quite going to work either. I should have said the values are _nearly_
> always integers, but they can be text (alphanumeric). So the general case
> is to compare anything to anything where there is a high likelihood of
> values being integers.

SELECT * FROM test WHERE (CASE WHEN (A = 1) THEN 1 WHEN (CAST(A AS INT) 
= 1) THEN 1 ELSE 0 END);

But as Igor mentioned, casting anything to integer that isn't castable 
to Integer produces 0, and even if it produced null you could use 
IFNULL() or COALESCE().

Or do you sometimes need to check for other things than just 1?

Reply via email to