Код ошибки 1292 mysql

I am not sure what is this error!

#1292 - Truncated incorrect DOUBLE value: 

I don’t have double value field or data!

I have wasted a whole hour trying to figure this out!

here is my query

INSERT INTO call_managment_system.contact_numbers 
    (account_id, contact_number, contact_extension, main_number, created_by)
SELECT
    ac.account_id,
    REPLACE(REPLACE(REPLACE(REPLACE(ta.phone_number, '-', ''), ' ', ''), ')', ''),'(','') AS Phone,
    IFNULL(ta.ext, '') AS extention,
    '1' AS MainNumber,
    '2' AS created_by
FROM 
    cvsnumbers AS ta
    INNER JOIN accounts AS ac ON ac.company_code = ta.company_code
WHERE 
    LENGTH(REPLACE(REPLACE(REPLACE(REPLACE(ta.phone_number, '-', ''), ' ', ''), ')', ''),'(','') ) = 10

here is my show create table for the table which the results are going into

CREATE TABLE `contact_numbers` (  
    `number_id` int(10) unsigned NOT NULL AUTO_INCREMENT,  
    `account_id` int(10) unsigned NOT NULL DEFAULT '0',  
    `person_id` int(11) NOT NULL DEFAULT '0',  
    `contact_number` char(15) NOT NULL,  
    `contact_extension` char(10) NOT NULL DEFAULT '',  
    `contact_type` enum('Primary','Direct','Cell','Fax','Home','Reception','Office','TollFree') NOT NULL DEFAULT 'Primary',  
    `contact_link` enum('Account','PDM','Other') NOT NULL DEFAULT 'Account',  
    `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '0 = inactive, 1=active', 
    `main_number` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1 = main phone number',  
    `created_on` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,  
    `created_by` int(11) NOT NULL,  
    `modified_on` datetime DEFAULT NULL,  
    `modified_by` int(11) NOT NULL DEFAULT '0',  
    PRIMARY KEY (`number_id`),  
    KEY `account_id` (`account_id`),  
    KEY `person_id` (`person_id`)
) ENGINE=InnoDB AUTO_INCREMENT=534 DEFAULT CHARSET=utf8

I am not sure what is this error!

#1292 - Truncated incorrect DOUBLE value: 

I don’t have double value field or data!

I have wasted a whole hour trying to figure this out!

here is my query

INSERT INTO call_managment_system.contact_numbers 
    (account_id, contact_number, contact_extension, main_number, created_by)
SELECT
    ac.account_id,
    REPLACE(REPLACE(REPLACE(REPLACE(ta.phone_number, '-', ''), ' ', ''), ')', ''),'(','') AS Phone,
    IFNULL(ta.ext, '') AS extention,
    '1' AS MainNumber,
    '2' AS created_by
FROM 
    cvsnumbers AS ta
    INNER JOIN accounts AS ac ON ac.company_code = ta.company_code
WHERE 
    LENGTH(REPLACE(REPLACE(REPLACE(REPLACE(ta.phone_number, '-', ''), ' ', ''), ')', ''),'(','') ) = 10

here is my show create table for the table which the results are going into

CREATE TABLE `contact_numbers` (  
    `number_id` int(10) unsigned NOT NULL AUTO_INCREMENT,  
    `account_id` int(10) unsigned NOT NULL DEFAULT '0',  
    `person_id` int(11) NOT NULL DEFAULT '0',  
    `contact_number` char(15) NOT NULL,  
    `contact_extension` char(10) NOT NULL DEFAULT '',  
    `contact_type` enum('Primary','Direct','Cell','Fax','Home','Reception','Office','TollFree') NOT NULL DEFAULT 'Primary',  
    `contact_link` enum('Account','PDM','Other') NOT NULL DEFAULT 'Account',  
    `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '0 = inactive, 1=active', 
    `main_number` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1 = main phone number',  
    `created_on` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,  
    `created_by` int(11) NOT NULL,  
    `modified_on` datetime DEFAULT NULL,  
    `modified_by` int(11) NOT NULL DEFAULT '0',  
    PRIMARY KEY (`number_id`),  
    KEY `account_id` (`account_id`),  
    KEY `person_id` (`person_id`)
) ENGINE=InnoDB AUTO_INCREMENT=534 DEFAULT CHARSET=utf8

I’m trying to update 2 different tables with an update query as shown below

UPDATE  db1.table1 a, db2.table1 b 
SET       b.firstname  =  a.firstname,
          b.lastname   =  a.lastname,
          b.address    =  a.address,
          b.state      =  a.state,
          b.city       =  a.city,
          b.zip        =  a.zip             

WHERE a.stud_id=b.stud_id AND a.firstname IS NOT NULL AND b.firstname IS NULL
          AND str_to_date(a.joindate,'%m/%d/%Y') >= str_to_date('02/01/2012','%m/%d/%Y');

but when i tried to execute this query, MySQL kept throwing the following error

Error Code: 1292. Truncated incorrect DOUBLE value: 'CROUGH0000'

Though i’ve found much similar posts in stackoverflow, i couldn’t find the exact solution to this problem.

Need some help. Thanks in advance


EDIT : Datatypes of each column are as follows

              b.firstname(varchar(25))  =  a.firstname(varchar(52)),
              b.lastname(varchar(25))   =  a.lastname(varchar(35)),
              b.address(varchar(40))    =  a.address(varchar(50)),
              b.state(char(2))      =  a.state(char(2)),
              b.city(varchar(25))       =  a.city(varchar(25)),
              b.zip(varchar(11))        =  a.zip(varchar(11))

MySQL error 1292 occurs if the syntax for the date is incorrectly entered.

Here at Bobcares, we have seen several causes for this error while troubleshooting MySQL issues as part of our Server Management Services for web hosts and online service providers.

Today we’ll take a look at the cause for this error and how to fix it.

Why does MySQL Error 1292 occur

Before we get into the solution part, let us first see what causes this error to occur.

This error normally occurs when the date is entered in an incorrect format. The date value like 0000-00-00 00:00:00 is not allowed with MySQL 5.7 version.

Also, this error can occur when trying to compare a number and a string in a WHERE or ON clause.

For instance, the error appears as below.

MySQL Error 1292

How we fix MySQL Error 1292

This error is of different types and can occur due to many reasons and also the solution will differ according to the error. Here are the different errors and the solutions that our Engineers provide to our customers.

1. If a field type is a DATE, then we make sure that the date is entered in the format “yyyy-mm-dd”.

2. Error Code: 1292 – Incorrect date value

Many of our customers use MySQL 5.7. But in this version date value like 0000-00-00 00:00:00 is not allowed. Hence, the above error occurs. In case, if our customers want to allow it, then we update their my.cnf like:

sudo nano /etc/mysql/my.cnf

In this file, we find

[mysqld]

Then after that, we add the below line.

sql_mode=”NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION”

After adding the above line, we restart the MySQL service. For that, we run the below command.

sudo service mysql restart

3. #1292 – Truncated incorrect DOUBLE value

Usually, this error message appears when customers try to compare a number and a string in a WHERE or ON clause.

So we make sure that they have similar declarations or convert the number to a string. Also, if we turn off strict mode, the error turns into a warning.

[Need any further assistance in fixing MySQL errors? – We’re available 24*7]

Conclusion

In short, this error can arise with different messages and has its own way to fix it. Today, we saw the resolution to this MySQL error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = «owonCMyG5nEQ0aD71QM»;

The MySQL error Truncated incorrect DOUBLE value is one of the weirdest errors in MySQL.

This is because the error can be caused by some mistakes in your SQL script that has nothing to do with a DOUBLE value.

The error is mostly triggered when there’s a mistake in UPDATE statements script.

Let’s see some example scripts that trigger the error. Suppose you have a database named students with the following data:

+----+---------+---------+-------+--------+-------------+
| id | name    | subject | score | gender | student_id  |
+----+---------+---------+-------+--------+-------------+
|  1 | Sarah   | Math    |     9 | male   | 12937254892 |
|  2 | Natalia | Math    |     8 | female | 08936A58421 |
|  3 | Christ  | English |     4 | male   | 87463X98107 |
+----+---------+---------+-------+--------+-------------+

One of the mistakes that could trigger the Truncated incorrect DOUBLE value error is when you use the AND clause when updating multiple columns of the table.

The script would look as follows:

UPDATE students 
  SET name = 'Sarah' 
    AND score = 9
  WHERE id = '1';
ERROR 1292 (22007): Truncated incorrect DOUBLE value: 'Sarah'

While the error is because of the AND clause, the error description will make you think that there’s something wrong with the value 'Sarah'.

To fix the error, you need to replace the AND clause with a comma:

UPDATE students 
  SET name = 'Sarah',
    score = 9
  WHERE id = '1';

-- Query OK, 0 rows affected (0.00 sec)
-- Rows matched: 1  Changed: 0  Warnings: 0

Another thing that could trigger this error is if you try to compare a string value that has no number representation with a number value in the WHERE clause.

An example wrong statement could be as shown below:

UPDATE students 
  SET score = 5
  WHERE student_id = 87463298107;

The error response would look as follows:

ERROR 1292 (22007): Truncated incorrect DOUBLE value: '08936A58421'

The error above is because there’s an entry in the student_id table that has no equal number value representation.

The student_id column is a VARCHAR column that can contain a string type of alphanumeric characters or a number type of numeric characters.

When you create a comparison in the WHERE clause that uses the number type, then MySQL will try to convert the column’s string type to number type for the comparison.

In the case of our example, the second row of the student_id column has no equal number value representation:

+-------------+
| student_id  |
+-------------+
| 12937254892 |
| 08936A58421 |
| 87463298107 |
+-------------+

The letter 'A' in the second row value causes MySQL unable to cast the value as an integer and do a comparison.

To fix the error, you need to wrap the value in the WHERE clause with quotation marks:

UPDATE students 
  SET score = 5
  WHERE student_id = '87463298107';

-- Query OK, 0 rows affected (0.00 sec)
-- Rows matched: 1  Changed: 0  Warnings: 0

Interestingly, MySQL won’t throw the same error when you run a SELECT statement:

SELECT * FROM students
  WHERE student_id = 87463298107;

The above query would return the result set without an error:

+----+--------+---------+-------+--------+-------------+
| id | name   | subject | score | gender | student_id  |
+----+--------+---------+-------+--------+-------------+
|  3 | Christ | English |     4 | male   | 87463298107 |
+----+--------+---------+-------+--------+-------------+

And those are some SQL script mistakes that can trigger the Truncated incorrect DOUBLE value error.

As you can see, the error can be triggered even when you don’t have any column of DOUBLE type or a DOUBLE value in your scripts.

If you found this error and are unable to find what’s wrong with your statements, then I suggest you check if the types used by your columns are the same as the types in your statements.

If you’re using VARCHAR type in your column, then it’s better to compare the column value with a string even though it looks like a number.

When there are values of different types, you can explicitly convert one of the values to match the other using the CAST() function.

Good luck in fixing the error! 👍

Понравилась статья? Поделить с друзьями:

Интересное по теме:

  • Код ошибки 1284 finereader что это
  • Код ошибки 1275 при установке кредо
  • Код ошибки 1275 при установке драйвера
  • Код ошибки 1275 при запуске игры
  • Код ошибки 1283

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии