update s set s.classbid = lc.itemid
from dbo.Lv_servers as s INNER JOINdbo.Lv_LineChannel as lc ON s.Classsid = lc.ClassId where s.classbid >0
SQL用另外一个表的数据更新本表数据,两个表的关系要写在from的后面表的别名也要写在这里,写在update后面是不行的,update后面跟着要更新的表,至于同时更新两表的数据暂时没有用过就 不知道了。
更新分类族谱 convert(nvarchar, s.id) int 转成nvarchar
/*更新一级分类*/
update T_Category set family=','+convert(nvarchar, id) +',' where lv=0/*更新二级分类*/update s set s.family = ','+convert(nvarchar, s.id) +sc.familyfrom dbo.T_Category as s left JOIN dbo.T_Category as sc ON s.headid = sc.id where s.lv =1 /*更新三级分类*/update s set s.family = ','+convert(nvarchar, s.id) +sc.familyfrom dbo.T_Category as s left JOIN dbo.T_Category as sc ON s.headid = sc.id where s.lv =2
posted on 2013-11-29 14:41 阅读( ...) 评论( ...)