日期:2014-05-17 浏览次数:20590 次
select distinct a=stuff((select ','''+convert(varchar,xh)+'''' from 表名 for xml path('')),1,1,'')
from 表名
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-03-20 17:00:49
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64)
-- Jun 17 2011 00:54:03
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1, v.721)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([xh] varchar(6),[no] varchar(2))
insert [huang]
select '110886','26' union all
select '080940','26' union all
select '050124','05' union all
select '050125','05' union all
select '050135','05' union all
select '070278','05' union all
select '050127','19' union all
select '050128','19' union all
select '050129','19' union all
select '050130','19' union all