update PosInStore set
CodePosOne=case
when CodePosOne=1-- then A   --成都
when CodePosOne=2-- then B   --重庆
我要更改分类表,第一级分类字段CodePosOne,第二级分类CodePosTwo,当找到1时,同时更改CodePosOne和CodePosTwo的值。
如何改写上面sql。上面那段只能改第一级CodePosOne的值。

解决方案 »

  1.   

    update PosInStore set CodePosOne='01',CodePosTwo='01' where CodePosOne='01--'
    类似这样,但我想一条sql解决,像下面那种,就可以一次改多个分类
    update PosInStore set
    CodePosOne=case
    when CodePosOne='01--' then '01' --成都
    when CodePosOne='02--' then '01' --重庆
    when CodePosOne='03--' then '01' --上海
    end
      

  2.   

    你就理解为:任何时候都两个字段,当不为1时,CodePosTwo = CodePosTwo;
      

  3.   

    declare @t1 table (col1 varchar(10), col2 varchar(10))
    insert into @t1 (col1, col2)
    select '01', '0000000000'
    union
    select '02', '0000000000'
    union
    select '03', '0000000000'
    union
    select '04', '0000000000'select * from @t1update @t1 set col1 = case when col1 = '01' then '成都'
       when col1 = '02' then '重庆'
       when col1 = '03' then '上海'
       when col1 = '04' then '纽约'
       end,
       col2 = case when col1 = '01' then '中国'
       when col1 = '02' then '中国'
       when col1 = '03' then '中国'
       when col1 = '04' then '美国'
       end
       
    select * from @t1