Incorrect DateTime Value '0000-00-00 00:00:00' - Date_Sub() in Having

前端 未结 2 1205
南方客
南方客 2020-12-11 07:10

So I have an insert which looks like this:

  INSERT INTO TempDupeData (Sys_InvoiceID, DupeSetID, Netted, InvoiceNo, InvoiceDate, Sys_SupplierID, SuppInvNo, N         


        
相关标签:
2条回答
  • 2020-12-11 07:38

    First option:

    This warning probably could be due to the SQL_MODE.

    According to mysql documentation "If the NO_ZERO_DATE or NO_ZERO_IN_DATE SQL mode is enabled, zero dates or part of dates are disallowed.". So this may be the cause your INSERT with '0000-00-00 00:00:00' fails.

    You can check your sql mode by executing this:

    SELECT @@sql_mode;
    

    and if any of the NO_ZERO_DATE or NO_ZERO_IN_DATE are set, then you can just:

    SET sql_mode = '';
    

    Second option

    The other option is it is failing because of the STRICT_TRANS_TABLES mode. As mysql documentation say:

    Strict mode affects whether the server permits '0000-00-00' as a valid date: If strict mode is not enabled, '0000-00-00' is permitted and inserts produce no warning. If strict mode is enabled, '0000-00-00' is not permitted and inserts produce an error, unless IGNORE is given as well. For INSERT IGNORE and UPDATE IGNORE, '0000-00-00' is permitted and inserts produce a warning

    The same is valid for datetime.

    So you have to either disable STRICT MODE OR if disabling it is not an option - modify the query so it doesn't return invalid date/datetime result

    0 讨论(0)
  • 2020-12-11 07:42

    Put this code before query

    SET sql_mode = '';
    

    or go to /etc/mysql/my.cnf & comment out STRICT_TRANS_TABLES

    useful note SQL STRICT MODE

    0 讨论(0)
提交回复
热议问题