Variable collation with MySQL stored procedure?
- by Chad Johnson
I want to do something like this in a stored procedure:
IF case_sensitive = FALSE THEN
SET search_collation = "utf8_unicode_ci";
ELSE
SET search_collation = "utf8_bin";
END IF;
INSERT INTO TABLE1 (field1, field2)
SELECT * FROM TABLE 2 WHERE some_field LIKE '%rarf%' collate search_collation;
However, when I do this, I get
ERROR 1273 (HY000): Unknown collation: 'search_collation'
How can I use a dynamic collation without having two copies of the same query?