当前位置: 代码迷 >> Sql Server >> 求SQL查询.解决方法
  详细解决方案

求SQL查询.解决方法

热度:59   发布时间:2016-04-27 12:55:36.0
求SQL查询.
SQL2000环境。
表结构如下:
列A |列B
1 |张三
1 |李四
1 |王五
1 |赵六

where 列A=1 时 想得到如下的查询结果

张三;李四;王五;赵六;

请教怎样取得。


------解决方案--------------------
declare @str varchar(2000)
set @str=''
select @[email protected]+B_';' from table
select left(@str,len(@str)-1)
SQL code

------解决方案--------------------
SQL code
declare @name nvarchar(2000)select @name = isnull(@name + ';','') + 列Bfrom 表where 列A = 1select @name as name
  相关解决方案