I'm working with a frustrating set of data that contains null, 0, 1, and 2 values for the 'active' column in my users table.
Why does this work:
SELECT u.id AS LegacyContactKey,
u.first_name AS FirstName,
u.last_name AS LastName,
c.company_name AS CompanyName,
u.email AS EmailAddress,
(CASE WHEN u.active = 1 THEN 1 WHEN u.active = 2 THEN 1 ELSE 0 END) as IsMember
FROM tb_users AS u
INNER JOIN tb_company AS c ON u.company_id = c.company_id
But not this?
SELECT u.id AS LegacyContactKey,
u.first_name AS FirstName,
u.last_name AS LastName,
c.company_name AS CompanyName,
u.email AS EmailAddress,
CAST((CASE WHEN u.active = 1 THEN 1 WHEN u.active = 2 THEN 1 ELSE 0 END) AS BOOLEAN) as IsMember
FROM tb_users AS u
INNER JOIN tb_company AS c ON u.company_id = c.company_id
I want to cast one of my query results as a boolean so it returns true or false but when I add CAST() I get an error (near BOOLEAN)
Running MariaDB 10.3