When I try to run a routine I get the following error:
Error Code: 1166. Incorrect column name 'School.`School Name` = case when School.`Web School Name` is null then School.`School Name` els'
I have double checked the column name and there is in fact a School.School Name
. There are no leading or trailing spaces. Here is the beginning of the routine that the error is referring to:
CREATE temporary TABLE tt_Step1
SELECT DISTINCT State.Code, State.Name,
School.`School Name` = case
when School.`Web School Name` is null then School.`School Name`
else School.`Web School Name`
end,
School.`School ID`
-- Into tt_Step1
FROM State LEFT JOIN School ON State.Code = School.State
Where (School.`School ID` <> ...
I recently converted this code from MSSQL to MySQL so there may be something I missed but I cannot find any errors. The original MSSQL query runs fine in SQL Server Management Studio but the converted version of it in MySQL does not.
Error Code: 1166. Incorrect column name 'School.`School Name` = case when School.`Web School Name` is null then School.`School Name` els' I have double checked the column name and there is in fact a School.School Name. There are no leading or trailing spaces. Here is the beginning of the routine that the error is referring to:
To conclude, the ERROR 1366: Incorrect string value happens when MySQL can’t insert the value you specified into the table because of incompatible encoding. You need to modify or remove characters that have 4-bytes UTF-8 encoding, or you can change the encoding and collation used by MySQL. Note that utf8 in MySQL always refers to utf8mb3.
You have spaces at the end of the names (for id and username ). This seems to be causing the problem, even though the escaped names are used consistently (this is documented in the MySQL documentation ). This works: I would expect the escaped characters to work. However, spaces at the end of the names is a bad idea, so remove them.
In my case, it was caused by an unseen extra space after the column name. I wrote promotion-ids
instead of promotion-id
.
Give this a shot:
CREATE temporary TABLE tt_Step1
SELECT DISTINCT State.Code, State.Name,
coalesce(School.`Web School Name`, School.`School Name`),
School.`School ID`
-- Into tt_Step1
FROM State LEFT JOIN School ON State.Code = School.State
Where (School.`School ID` <> ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With