急救,请各位大侠赐教!

fishidea 2010-01-20 09:12:12
表 A 如下:

cc name count
1 AA NULL
2 BB NULL
3 CC NULL
4 DD NULL


怎么能将count的值更新为 AA,BB,CC,DD ?

多谢大家指点,谢谢了~
...全文
96 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
pt1314917 2010-01-20
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 fishidea 的回复:]
谢谢回复,不对噢~我要查询出来的count的值是 AA,BB,CC,DD,

按您现在的这样,count的值是等于name的,如下:
cc name count
1  AA  AA
2  BB  BB
3  CC  CC
4  DD  DD
这是错的
[/Quote]
4、5楼早有正确答案了。。。
fishidea 2010-01-20
  • 打赏
  • 举报
回复
感谢SQL77与andysun88,结贴给分!^_^
andysun88 2010-01-20
  • 打赏
  • 举报
回复

declare @strs varchar(500)
set @strs=''
select @strs = @strs +','+name from A12
print @strs

select A12.cc,A12.name,@strs as count from A12
SQL77 2010-01-20
  • 打赏
  • 举报
回复
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',null

declare @str varchar(100)

select @str=isnull(@str+',','')+name from [A]

update A set [count]=@str WHERE [COUNT] IS NULL

select * from [A]
J1985Z 2010-01-20
  • 打赏
  • 举报
回复
update a set count=name
fishidea 2010-01-20
  • 打赏
  • 举报
回复
谢谢回复,不对噢~我要查询出来的count的值是 AA,BB,CC,DD,

按您现在的这样,count的值是等于name的,如下:
cc name count
1 AA AA
2 BB BB
3 CC CC
4 DD DD
这是错的
andysun88 2010-01-20
  • 打赏
  • 举报
回复

update A set count= name
nianran520 2010-01-20
  • 打赏
  • 举报
回复
--> 测试数据: [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',null

declare @str varchar(100)

select @str=isnull(@str+',','')+name from [A]

update A set [count]=@str

select * from [A]
pt1314917 2010-01-20
  • 打赏
  • 举报
回复

--> 测试数据: [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',null

declare @t varchar(100)
select @t=isnull(@t+',','')+name from a
update a set [count]=@t
select * from [A]
jwdream2008 2010-01-20
  • 打赏
  • 举报
回复
update a set [count]=[name]
--小F-- 2010-01-20
  • 打赏
  • 举报
回复
update tb set [count]=name
华夏小卒 2010-01-20
  • 打赏
  • 举报
回复
update a set count=name

22,301

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧