日期:2014-05-17 浏览次数:20448 次
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-01-06 14:54:40
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
-- Dec 28 2012 20:23:12
-- Copyright (c) Microsoft Corporation
-- Enterprise 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]([name] varchar(18))
insert [huang]
select '1,2,3,4,abc,dresas'
--------------开始查询--------------------------
select
SUBSTRING(a.[name],number,CHARINDEX(',',a.[name]+',',number)-number) as [name]
from
[huang] a,master..spt_values
where
number >=1 and number<=len(a.[name])
and type='p'
and substring(','+a.[name],number,1)=','
----------------结果----------------------------
/*
name
------------------
1
2
3
4
abc
dresas
*/