日期:2014-05-17 浏览次数:20572 次
CREATE TABLE [dbo].[Table_1](
[a] [varchar](50) NULL
) ON [PRIMARY]
insert into [Table_1](a) values('aaa');
insert into [Table_1](a) values('bbb');
insert into [Table_1](a) values('eee');
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-08-14 12:36:43
-- Version:
-- Microsoft SQL Server 2014 (CTP1) - 11.0.9120.5 (X64)
-- Jun 10 2013 20:09:10
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([key] varchar(23))
insert [huang]
select 'aaa,bbb,ccc,ddd,eee,fff'
CREATE?TABLE?[dbo].[Table_1](
????[a]?[varchar](50)?NULL
)?ON?[PRIMARY]
insert?into?[Table_1](a)?values('aaa');
insert?into?[Table_1](a)?values('bbb');
insert?into?[Table_1](a)?values('eee');
--------------开始查询--------------------------
SELECT * FROM
(
SELECT distinct
SUBSTRING([key],number,CHARINDEX(',',[key]+',',number)-number) as [key]
from
[huang] a,master..spt_values
where
number >=1 and number<len([key])