参考: If Object_Id('Split') Is Not NULL Drop Function Split GOCreate Function Split(@Sql varchar(8000),@Splits varchar(10)) returns @temp Table (a varchar(100)) As Begin Declare @i Int Set @Sql = RTrim(LTrim(@Sql)) Set @i = CharIndex(@Splits,@Sql) While @i >= 1 Begin Insert @temp Values(Left(@Sql,@i-1)) Set @Sql = SubString(@Sql,@i+1,Len(@Sql)-@i) Set @i = CharIndex(@Splits,@Sql) EndIf @Sql <> '' Insert @temp Values (@Sql) Return End/* 例: Select * from dbo.Split('0:418001:418002:418002',':') */
If Object_Id('Split') Is Not NULL
Drop Function Split
GOCreate Function Split(@Sql varchar(8000),@Splits varchar(10))
returns @temp Table (a varchar(100))
As
Begin
Declare @i Int
Set @Sql = RTrim(LTrim(@Sql))
Set @i = CharIndex(@Splits,@Sql)
While @i >= 1
Begin
Insert @temp Values(Left(@Sql,@i-1))
Set @Sql = SubString(@Sql,@i+1,Len(@Sql)-@i)
Set @i = CharIndex(@Splits,@Sql)
EndIf @Sql <> ''
Insert @temp Values (@Sql)
Return
End/*
例:
Select * from dbo.Split('0:418001:418002:418002',':')
*/