--如果tb_cl表中的flxdz、fyb、fprovince、fcity、farea为空,则将tb_kh表中的相关信息更新过来,原来的语句如下:update b set b.fprovince=(case b.fprovince when '' then isnull(a.fprovince,'') else b.fprovince end),
b.farea=(case when b.farea='' then (isnull(a.farea,'')) else b.farea end),
b.fcity=(case when b.fcity='' then isnull(a.fcity,'') else b.fcity end),
b.flxdz=(case when b.flxdz='' then (isnull(a.fdz,'')) else b.flxdz end),
b.fyb=(case when b.fyb='' then (isnull(a.fyb,'')) else b.fyb end) from tb_cl b,tb_kh a where b.fkhh=a.fkhh--公司一哥们非说上面的语句有问题,说在他的电脑上执行有“sql server连接有误”,其实不是真实的错误,因为执行其他sql语句没问题,一执行到上面这条语句就报错。但是同样的数据库在我的电脑上执行,却没有任何问题。后来他把上面的语句优化为下面的语句,大家看是不是需要优化或者是不是有更好的办法:
1、update tb_cl set fprovince = a.fprovince from tb_cl b with(nolock) join tb_kh a with(nolock) on a.fkhh = b.fkhh where LEN(b.fprovince) = 02、update tb_cl set farea= a.farea from tb_cl b with(nolock) join tb_kh a with(nolock) on a.fkhh = b.fkhh where LEN(b.farea) = 03、update tb_cl set fcity= a.fcity from tb_cl b with(nolock) join tb_kh a with(nolock) on a.fkhh = b.fkhh where LEN(b.fcity) = 04、update tb_cl set flxdz= a.fdz from tb_cl b with(nolock) join tb_kh a with(nolock) on a.fkhh = b.fkhh where LEN(b.flxdz) = 05、update tb_cl set fyb= a.fyb from tb_cl b with(nolock) join tb_kh a with(nolock) on a.fkhh = b.fkhh where LEN(b.fyb) = 0就是把前面的语句分开一条一条来更新,请高手指点……