Hi i need to replace an integer field with the respective text, it is not a variable thing, using a join would be a waste for this.
The table structure is
CREATE TABLE `mesas_cab` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cid` int(11) DEFAULT NULL,
`vid` int(11) DEFAULT NULL,
`status` int(11) DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
and my query is
SELECT
mesas_cab.id,
mesas_cab.cid,
mesas_cab.vid,
mesas_cab.status,
usuarios.NOME,
clientes.RAZAOSOCIAL,
CASE mesas_cab.status
WHEN 0 THEN 'Livre'
WHEN 1 THEN 'Ocupada'
WHEN 2 THEN 'Fechada'
END CASE as status_str
FROM
mesas_cab
LEFT JOIN usuarios ON mesas_cab.vid = usuarios.CODIGO
LEFT JOIN clientes ON mesas_cab.cid = clientes.CODIGO
i have seen this answer replace integer with string in query
but my query is still giving me syntax errors
[SQL] SELECT
mesas_cab.id,
mesas_cab.cid,
mesas_cab.vid,
mesas_cab.status,
usuarios.NOME,
clientes.RAZAOSOCIAL,
CASE mesas_cab.status
WHEN 0 THEN 'Livre'
WHEN 1 THEN 'Ocupada'
WHEN 2 THEN 'Fechada'
END CASE as status_str
FROM
mesas_cab
LEFT JOIN usuarios ON mesas_cab.vid = usuarios.CODIGO
LEFT JOIN clientes ON mesas_cab.cid = clientes.CODIGO
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CASE as status_str
FROM
mesas_cab
LEFT JOIN usuarios ON mesas_cab.vid = usuar' at line 12
but when i remove the whole case statement the query works almost as planned(the joins are okay)
CASEafter theENDi.e.CASE mesas_cab.status ... END AS status_strstatusvalues.