SQL Split
CREATE FUNCTION dbo.dhg_splitstr ----- 2006-6-21 17:00 过滤函数
(
@SourceSql varchar(8000),
@StrSeprate varchar(10)
)
RETURNS @temp table(A1 int identity(1,1) not null, F1 varchar(100))
AS
BEGIN
declare @i int
set @SourceSql=rtrim(ltrim(@SourceSql))
set @i=charindex(@StrSeprate,@SourceSql)
while @i>=1
begin
insert @temp values(left(@SourceSql,@i-1))
set @SourceSql=subString (@SourceSql,@i+1,len(@SourceSql)-@i)
set @i=charindex(@StrSeprate,@SourceSql)
end
if @SourceSql<>''
insert @temp values(@SourceSql)
RETURN /* value */
END
=====================================================================
*****************************************************************************
* Name: T-SQL Split算法实现(整型)
* Author: Xinsoft
* Create Date: 2004-12-01
* Version: V1.0.00
*****************************************************************************/
CREATE Function Func_SplitInt
(
@InputStr varchar(250)
)
Returns @Func_SplitInt table
(
val int
)
as
Begin
Declare @str varchar(250)
Declare @substr varchar(250)
Declare @iLen int
Declare @iStart int
set @str=RTrim(Ltrim(@InputStr))
set @iStart=CHARINDEX( ',' , @str )
set @iLen=Len( @str )
IF @iStart>0
Begin
set @substr=substring( @str , 1 , @iStart-1 )
set @str=substring( @str , @iStart+1 , @iLen-@iStart )
End
Else
Begin
set @substr=@str
set @str=''
End
set @substr=RTRIM( LTRIM( @substr ) )
insert @Func_SplitInt select id=cast( @substr as int )
While Len( @str )>0
Begin
---------------- Loop Begin ---------------
set @iStart=CHARINDEX( ',' , @str )
set @iLen=Len( @str )
IF @iStart>0
Begin
set @substr=substring( @str , 1 , @iStart-1 )
set @str=substring( @str , @iStart+1 , @iLen-@iStart )
End
Else
Begin
set @substr=@str
set @str=''
End
set @substr=RTRIM( LTRIM( @substr ) )
insert @Func_SplitInt select id=cast( @substr as int )
---------------- Loop End ----------------
End
Return
End
(
@SourceSql varchar(8000),
@StrSeprate varchar(10)
)
RETURNS @temp table(A1 int identity(1,1) not null, F1 varchar(100))
AS
BEGIN
declare @i int
set @SourceSql=rtrim(ltrim(@SourceSql))
set @i=charindex(@StrSeprate,@SourceSql)
while @i>=1
begin
insert @temp values(left(@SourceSql,@i-1))
set @SourceSql=subString (@SourceSql,@i+1,len(@SourceSql)-@i)
set @i=charindex(@StrSeprate,@SourceSql)
end
if @SourceSql<>''
insert @temp values(@SourceSql)
RETURN /* value */
END
=====================================================================
*****************************************************************************
* Name: T-SQL Split算法实现(整型)
* Author: Xinsoft
* Create Date: 2004-12-01
* Version: V1.0.00
*****************************************************************************/
CREATE Function Func_SplitInt
(
@InputStr varchar(250)
)
Returns @Func_SplitInt table
(
val int
)
as
Begin
Declare @str varchar(250)
Declare @substr varchar(250)
Declare @iLen int
Declare @iStart int
set @str=RTrim(Ltrim(@InputStr))
set @iStart=CHARINDEX( ',' , @str )
set @iLen=Len( @str )
IF @iStart>0
Begin
set @substr=substring( @str , 1 , @iStart-1 )
set @str=substring( @str , @iStart+1 , @iLen-@iStart )
End
Else
Begin
set @substr=@str
set @str=''
End
set @substr=RTRIM( LTRIM( @substr ) )
insert @Func_SplitInt select id=cast( @substr as int )
While Len( @str )>0
Begin
---------------- Loop Begin ---------------
set @iStart=CHARINDEX( ',' , @str )
set @iLen=Len( @str )
IF @iStart>0
Begin
set @substr=substring( @str , 1 , @iStart-1 )
set @str=substring( @str , @iStart+1 , @iLen-@iStart )
End
Else
Begin
set @substr=@str
set @str=''
End
set @substr=RTRIM( LTRIM( @substr ) )
insert @Func_SplitInt select id=cast( @substr as int )
---------------- Loop End ----------------
End
Return
End