主表的主键id--自动增长
从表的外键aid
主表有个列 number
在从表里有个列text
当列中有内容后 number增加1update 主表
set number = number + 1
where ??????????????理不清他们的关系..............是如何关联的???????请前辈赐教

解决方案 »

  1.   

    update 主表
    set number = number + 1
    from 主表,从表
    where 主表.id=从表.aid and 从表.text列 is not null
      

  2.   

    update 主表
    set number = number + 1
    from 主表,从表 --这里的话,只需要写表,不需要写列是吗
    where 主表.id=从表.aid and 从表.text列 is not null
      

  3.   

    --tryupdate 主表
    set number = isnull(number,0) + [count]
    from (select aid,count(*) as [count] from 从表 where text列名 is not null group by aid) 从表
    where 主表.id=从表.aid
      

  4.   

    按lianqizhi(油条豆腐脑) 
    的弄好了gahade(与君共勉) 的好多新函数...............学习中...........
      

  5.   

    按你说的主从表结构,应该是主表的1个id可对应从表的多个aid,就是一对多.如果从表多个aid的text列都有内容时应该得到汇总的数量更新到主表的number上.
      

  6.   

    我执行了
    update 主表
    set number = number + 1
    from 主表,从表 --这里的话,只需要写表,不需要写列是吗
    where 主表.id=从表.aid and 从表.text列 is not null这个影响了1条记录但是我的从表有4条记录是基本相同的(只有前面一列的从表ID列不同[自动增长])为什么只影响一列呢?