mysql下的将一个字段名的值复制到另一个字段名中(批量更新数据)

由于业务需求的更改,将原本两个下拉框合并成为一个下拉框,数据库的一些字段不在需要,而将不需要的字段对应的数据复制到其它字段中去,保证数据不丢失。类似
[code="java"]
update crm_activity set entityType = 1,entityID = (select linkID from crm_activity where linkType = 2 ) ,entityName = (select linkName from crm_activity where linkType = 2) where linkType = 2
[/code]

可以使用CONCAT函数,还要使用ifnull判断是否空
update xxx set a=CONCAT(ifnull(b,''),ifnull(c,''),ifnull(ADDRESS_TOWN,'')) ;

[code="sql"]

update crm_activity set entityType = 1, entityID = linkID ,entityName = linkName

[/code]

这个应该是你要的吧!

[quote]如果两个字段的值组合到一个字段中去

update crm_activity set entityType = entityID + entityName; 这样是不行的。
[/quote]

如果你的需求是合并字段,那么要使用连接符号

[code="sql"]update crm_activity set entityType = entityID||entityName;
如果是类型问题,那么你需要转换下类型
update crm_activity set entityType = to_char(entityID)||to_char(entityName);[/code]

SQL中的字符连接不是java语法中的+,也不是php语法中的点号,而是 双竖线||