日期:2014-05-19  浏览次数:20638 次

SQL如何实现

字段A
,123,124,125,

查询显示

字段A
123
124
125
请问如何实现

------解决方案--------------------
Create Table A
(A Varchar(100))
Insert A Select ',123,124,125, '
GO
Select Top 100 ID = Identity(Int, 1, 1) Into #T From Syscolumns A, Syscolumns B

Select
A = Substring(A.A, B.ID, CharIndex( ', ', A.A + ', ', B.ID) - B.ID)
From A, #T B
Where Substring( ', ' + a.A, B.id, 1) = ', ' And Substring(A.A, B.ID, CharIndex( ', ', A.A + ', ', B.ID) - B.ID) != ' '
Order By A

Drop Table #T
GO
Drop Table A
--Result
/*
A
123
124
125
*/