0

I have the following table:

CREATE TABLE `providers` (
  `id` int(10) NOT NULL auto_increment,
  `name` varchar(255) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `id` (`id`),
) ENGINE=InnoDB AUTO_INCREMENT=1392 DEFAULT CHARSET=latin1;

I try to contact id and name in a query:

SELECT id, name, CONCAT("[", id, "] ", name) AS value FROM providers;

It works great for most entries. However, when name has characters with accents, I get a malformed string:

+-----+-------------------------+-------------------------+
| id  | name                    | value                   |
+-----+-------------------------+-------------------------+
| 138 | ÁREA TECNOLÓGICA        | [138] �REA TECNOL�GICA  |
+-----+-------------------------+-------------------------+

Is there any way to fix it in the SQL level?

guyaloni
  • 4,972
  • 5
  • 52
  • 92

1 Answers1

0

Ok, I found the solution, I leave it here in case it will help somebody:

When you try to concat different types, this is what happens. So the solution is to use casting:

SELECT id, name, CONTACT("[", CONVERT(id, CHAR(8)), "] ", name) AS value 
FROM `providers`;
Cid
  • 14,968
  • 4
  • 30
  • 45
guyaloni
  • 4,972
  • 5
  • 52
  • 92