sql update语句,急!
如题
title body
2 4
2 空白
我想实现一个功能!选择当title相同时,自动选择有数据(不为空)的body ,然后将title相同的其他空白 body列数据 update掉!
求写法,谢谢
[解决办法]
自己写一个存储过程,
先获取body不为空的数据
再updatebody为空的数据
[解决办法]
update tb set body=bd from (select max(body)bd,title from tb group by title)t where t.title=tb.title and isnull(tb.body,'')=''
[解决办法]
选择相同的title有数据的body,你可以按body倒序排
select * from 表 where title=2 order by body desc;
更新就加个条件 where body is null
update 表 set body = 某个值 where title=2 and isnull(body,'')=''
[解决办法]
你要是将为空的body更新 与body不为空的记录 一样,则改成
update 表 A set body = (select top 1 body from 表 where title=A.title order by body desc) where title=2 and isnull(body,'')=''
[解决办法]
[code=sql]
SELECT DISTICUT * (SELECT * FROM TABLE WHERE body NOT NULL)
AS TEMP
[/ code]
[解决办法]
你说的那个 update 你要自己在细化下
如果出现下面的情况你就要自己吧条件说明了
title body
2 4
2 \"\"
2 新增
2 [null]
2 /s
这种请款你要选择哪个作为更新源才能决定 符合 update 的写法。
[解决办法]
isnull(body,'')=''
意思是如果body为null,先将null转成''
等价于 body is null or body=''