日期:2014-05-17 浏览次数:20616 次
select stuff((select distinct ','+scno
from sccidtl for xml path('')),1,1,'') 'scnos'
----------------------------
-- Author :DBA_Huanzj(發糞塗牆)
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3000.0 (X64)
-- Oct 19 2012 13:38:57
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([scno] varchar(53))
insert [huang]
select 'PI12060001,PI12070002,PI12080004,PI12080005,PI1208000'
--------------开始查询--------------------------
select
SUBSTRING([scno],number,CHARINDEX(',',[scno]+',',number)-number) as [scno]
from
[huang] a,master..spt_values
where
number >=1 and number<len([scno])
and type='p'
and substring(','+[scno],number,1)=','
----------------结果----------------------------
/*
scno
-----------------------------------------------------
PI12060001
PI12070002
PI12080004
PI12080005
PI1208000
*/
declare @tab table(val varchar(10))