Column concatenation returns “Null” Mysql - Php

二次信任 提交于 2019-12-25 06:49:15

问题


I can able to concatenate the values using the following code

$sqlselect = "UPDATE billing_details SET SRF = CONCAT(Year, ID)";

but it returns the result value as "NULL". Kindly help me to solve this issue

Table Structure:

Year *Varchar(5)*

ID *Int(10)*

SRF *Varchar(100)*

Result Table:

Year Id SRF

A 1 NULL

A 2 NULL

A 3 NULL


回答1:


MySql CONCAT function is return NULL if any argument value if null value, see blow

SELECT COCAT(NULL, 1) 

OR

SELECT COCAT(1, NULL)

>NULL

If you want to keep other values while any argument value have null then use IFNULL() function to exclude NULL values

In your query

$sqlselect = "UPDATE billing_details SET SRF = CONCAT(IFNULL(Year, ''), IFNULL(ID, ''))";


来源:https://stackoverflow.com/questions/26711668/column-concatenation-returns-null-mysql-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!