各位高人前辈,帮忙看看这个句子update tc_customer 
set cust_int029=case  when
(tc_friend.friend_simple_code like'6688%' or tc_friend.friend_simple_code like'8866%' 
or tc_friend.friend_simple_code like '6666%') and tc_friend.friend_id=tc_customer.friend_id and owner_id=1 
then '1001' else '1002'end这个句子有问题,
两张表tc_customer,tc_friend,想看到的结果是当表tc_friend.friend_simple_code =6688或8866或6666是,把表tc_customer 的cust_int029 改成1001,其他情况改成1002

解决方案 »

  1.   

    update a set cust_int029=case  when 
    (b.friend_simple_code in('6688','8866','6666') then '1001' else '1002' end 
    from tc_customer  a,tc_friend b 
    where b.friend_id=a.friend_id and a.owner_id=1 
      

  2.   

    try
    update tc_customer
    set cust_int029=case  when
    (tc_friend.friend_simple_code like'6688%' or tc_friend.friend_simple_code like'8866%'
    or tc_friend.friend_simple_code like '6666%') and  then '1001' else '1002'end  from tc_friend 
    where tc_friend.friend_id=tc_customer.friend_id and owner_id=1
      

  3.   


    update tc_customer 
    set cust_int029=case  when tc_friend.friend_simple_code like'6688%' then '1001' else '1002'end ,
                          when tc_friend.friend_simple_code like'8866%' then '1001' else '1002'end ,
                          when tc_friend.friend_simple_code like '6666%' then '1001' else '1002'end 
    where tc_friend.friend_id=tc_customer.friend_id and owner_id=1 
      

  4.   

    update a 
    set a.cust_int029=case when b.friend_simple_code in('6688','8866','6666') then '1001' else '1002' end 
    from tc_customer  a
      join tc_friend b 
        on a.friend_id=b.friend_id
        and a.owner_id=1 
      

  5.   

    如果就只有'6688','8866','6666'就用in 如果是'6688'只是一部分的话 用like
      

  6.   

    update a 
    set a.cust_int029=case when b.friend_simple_code like'6688%' or b.friend_simple_code like'8866%' or b.friend_simple_code like '6666%' then '1001' else '1002' end  
    from tc_customer  a
      join tc_friend b 
        on a.friend_id=b.friend_id
        and a.owner_id=1 
    这样再试试
      

  7.   

    update tc_customer 
    set cust_int029=case  when f.friend_simple_code like '6688%'
                          or f.friend_simple_code like '8866%'
                          or f.friend_simple_code like '6666%' then '1001'
                          else '1002'
                    end
    from tc_customer c
    inner join tc_friend f
    on f.friend_id=c.friend_id 
    where c.owner_id=1 
      

  8.   

    这样就OK了。update tc_customer 
    set cust_int029= (case  when 
    (tc_friend.friend_simple_code like'6688%' or 
     tc_friend.friend_simple_code like'8866%' or 
     tc_friend.friend_simple_code like '6666%') and 
    tc_friend.friend_id=tc_customer.friend_id and owner_id=1 
    then '1001' else '1002'end) 
    FROM tc_customer  
      

  9.   


    update tc_customer 
    set cust_int029=case  when tc_friend.friend_simple_code like'6688%' then '1001' else '1002'end ,
                          when tc_friend.friend_simple_code like'8866%' then '1001' else '1002'end ,
                          when tc_friend.friend_simple_code like '6666%' then '1001' else '1002'end 
    where tc_friend.friend_id=tc_customer.friend_id and owner_id=1 应该是这样,在WHEN 里面条件不能那样连接