日期:2014-05-17 浏览次数:20398 次
/****** Object: UserDefinedFunction [dbo].[fnSys_SplitString] Script Date: 03/19/2013 15:22:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*
功能说明:传入字符串跟分割符('''SGHE00000003'',''SGHE00000004'',''SGHE00000005'''),返回一个Table
*/
ALTER function [dbo].[fnSys_SplitString]
(
---字符串分割
@Str varchar(max), --传入的字符串
@SeprateStr varchar(10)--分隔符
)
Returns @temp table(Code varchar(100)) --返回一个Table
As
Begin
Declare @i int
Set @Str=REPLACE(@str,'''','')
Set @Str =rtrim(ltrim(@Str ))
Set @i=charindex(@SeprateStr,@Str )
While @i>=1
Begin
Insert @temp values(left(@Str ,@i-1))
Set @Str =substring(@Str ,@i+1,len(@Str )-@i)
Set @i=charindex(@SeprateStr,@Str )
End
If @Str <>''
Insert @temp values(@Str )
Return
End
DECLARE @TempStr VARCHAR(20)
SET @TempStr ='xx.exe
------解决方案--------------------
0'
DECLARE @Temp TABLE
(
[name] VARCHAR(10),
[value] tinyint
)
insert into @Temp
select left(@TempStr,charindex('
------解决方案--------------------
',@TempStr)-1),right(@TempStr,len(@TempStr)-charindex('
------解决方案--------------------
',@TempStr))
-- 这里怎么写?
select * from @Temp
/*
name value
----------------
xx.exe 0
*/
DECLARE @TempStr VARCHAR(20)
SET @TempStr ='xx.exe
------解决方案--------------------
0'
DECLARE @Temp TABLE
(
[name] VARCHAR(10),
[value] tinyint
)
insert into @Temp ([name],[value])
select substring(@TempStr,1,charindex('
------解决方案--------------------
',@TempStr)-1),
substring(@TempStr,charindex('