表 A 如下:cc name count
1  AA   NULL
2  BB   NULL
3  CC   NULL
4  DD   NULL
怎么能将count的值更新为 AA,BB,CC,DD ?多谢大家指点,谢谢了~

解决方案 »

  1.   

    update a set count=name
      

  2.   

    update tb set [count]=name
      

  3.   

    update a set [count]=[name]
      

  4.   


    --> 测试数据: [A]
    if object_id('[A]') is not null drop table [A]
    create table [A] (cc int,name varchar(2),count varchar(20))
    insert into [A]
    select 1,'AA',null union all
    select 2,'BB',null union all
    select 3,'CC',null union all
    select 4,'DD',nulldeclare @t varchar(100)
    select @t=isnull(@t+',','')+name from a
    update a set [count]=@t
    select * from [A]
      

  5.   

    --> 测试数据: [A]
    if object_id('[A]') is not null drop table [A]
    create table [A] (cc int,name varchar(2),count varchar(20))
    insert into [A]
    select 1,'AA',null union all
    select 2,'BB',null union all
    select 3,'CC',null union all
    select 4,'DD',nulldeclare @str varchar(100)select @str=isnull(@str+',','')+name from [A]update A set [count]=@strselect * from [A]
      

  6.   


    update A set count= name 
      

  7.   

    谢谢回复,不对噢~我要查询出来的count的值是 AA,BB,CC,DD,按您现在的这样,count的值是等于name的,如下:
    cc name count 
    1  AA  AA 
    2  BB  BB
    3  CC  CC
    4  DD  DD
    这是错的
      

  8.   

    update a set count=name
      

  9.   

    if object_id('[A]') is not null drop table [A]
    create table [A] (cc int,name varchar(2),count varchar(20))
    insert into [A]
    select 1,'AA',null union all
    select 2,'BB',null union all
    select 3,'CC',null union all
    select 4,'DD',nulldeclare @str varchar(100)select @str=isnull(@str+',','')+name from [A]update A set [count]=@str WHERE [COUNT] IS NULLselect * from [A]
      

  10.   


    declare @strs varchar(500)
    set @strs=''
    select @strs = @strs +','+name from A12
    print @strsselect A12.cc,A12.name,@strs as count from A12
      

  11.   

    感谢SQL77与andysun88,结贴给分!^_^