update b
set a = (select count(列1) from 表2 ),b =  (select sum(列2) from 表2 ),
from 表1 b
这个写法比只更新一列要慢一倍,有什么简化方法吗下面这种方法好象不行说错误update b
set (a,b) = (select count(列1),sum(列2) from 表2)
from 表1 b
谢谢大家

解决方案 »

  1.   

    --用變量
    DECLARE @I INT
    select @INT=count(列1) from 表2 update b
    set a =@I,b =  @I 
    from 表1 b 
      

  2.   

    UPDATE A SET
        a = B.rowcnt,
        b = B.rowsum
    FROM tb1 AS A,
      (SELECT COUNT(col1) AS rowcnt,SUM(col2) AS rowsum FROM tb) AS B;
      

  3.   

    DECLARE @I INT
    select @INT=count(列1) from 表2 DECLARE @B INT
    select @B=SUM(列2) from 表2 update b
    set a =@I,b =  @B
    from 表1 b 
      

  4.   

    DECLARE @I INT
    select @I=count(列1) from 表2 DECLARE @B INT
    select @B=SUM(列2) from 表2 update b
    set a =@I,b =  @B
    from 表1 b 
    宝鸭名字都不打对,呼呼
      

  5.   

    update b 
    set a = t.a,b = t.b
    from 表1 b ,
      (select count(列1) a,sum(列2) b  from 表2) t
      

  6.   

    update 
        a 
    set
        a = B.rowcnt,
        b = B.rowsum
    from 
        tb1 a,(select count(col1)  rowcnt,sum(col2)  rowsum from tb) B;
      

  7.   

    update 
        a 
    set 
        a = B.rowcnt, 
        b = B.rowsum 
    from 
        tb1 a,(select count(col1)  rowcnt,sum(col2)  rowsum from tb) B;
      

  8.   

    update b 
    set a =  count(列1) ,
    b =   sum(列2) 
    from 表1 b 
    ,表2
      

  9.   

    --try
    update b 
    set a = (select rows from sysindexes where id=object_id('表2') and indid=0 ),b =  (select sum(列2) from 表2 )
    from 表1  b
      

  10.   

    1:
    ;
    with cte1 as
    ( select * from b,(select count(列1) rowcnt1,count(列2) rowcnt2 from 表2) B
    )update cte1 set a=rowcnt1,b=rowcnt2
    2:t-sql到目前为止还不支持行值构造器,虽然Ansi支持
      

  11.   


    会提示:无法绑定由多个部分组成的标识符 b.aaaupdate b 
    set a = t.a,b = t.b
    from 表1 b ,
      (select count(列1) a,sum(列2) b  from 表2 where b.aaa = 1) t麻烦大家了
      

  12.   


    update b 
    set a = t.a,b = t.b 
    from 表1 b , 
      (select count(列1) a,sum(列2) b  from 表2 ) t 
    where b.aaa=1
    试试
      

  13.   

    update b 
    set a = t.a,b = t.b 
    from 表1 b , 
      (select count(列1) a,sum(列2) b  from 表2 where aaa = 1) t 
    把B给去掉.
      

  14.   

    update b 
    set a = t.a,b = t.b 
    from 表1 b , 
      (select count(列1) a,sum(列2) b  from 表2) t 
    where b.aaa=1如果你的aaa在表1,这样.
      

  15.   

    update b 
    set a = t.a,b = t.b 
    from 表1 b , 
      (select count(列1) a,sum(列2) b  from 表2 where aaa = 1) t 
      

  16.   


    update b set b.a=a.a,b.b=a.b
    from 表1 b,(select count(列1) a,max(列2) b from 表2) a
      

  17.   

    update b 
    set a = t.a,b = t.b 
    from 表1 b , 
      (select count(列1) a,sum(列2) b  from 表2 where b.列3 = 列3) t 还是没解决哦,,,我条件里一定会有一个  B 的提示:无法绑定由多个部分组成的标识符 b.列3