从WT1_1NB_B1表中找到C7长度是9的,把C7的内容赋值到SECU_DEPARTMENT 中的dept_xzjdcode字段中,WT1_1NB_B1中的USERID_与SECU_DEPARTMENT中的DEPT_ID 关联,并且要求WT1_1NB_B1中的BBQ_是 '2007---'的,请教各位应该怎么写?
我这么写好像不对
update secu_department a set a.dept_xzjdcode=(select b.c7 from wt1_1nb_b1 b 
where b.userid_=a.dept_id and b.bbq_='2007----' and length(b.c7)=9) 
where  exists (select 1 from wt1_1nb_b1 b where 
b.userid_=a.dept_id and b.bbq_='2007----' and length(b.c7)=9)

解决方案 »

  1.   

    update secu_department  AA set AA.dept_xzjdcode = (select C7 from WT1_1NB_B1 where USERID = AA.DEPT_ID and BBQ like('2007%') and length(C7) = 9 )
      

  2.   

    update secu_department a 
    set a.dept_xzjdcode=
    (select b.c7 from wt1_1nb_b1 b 
    where b.userid_=a.dept_id and b.bbq_='2007----' and length(b.c7)=9) where  exists (select 1 from wt1_1nb_b1 b where 
    b.userid_=a.dept_id and b.bbq_='2007----' and length(b.c7)=9) --------------------------------------------
    问题是:set后面的sql和exists里的一样了,应该是exists里面要比set的多个关联条件
    应该是exists缺个条件