今天写到的一个函数create function [dbo].[split](@SourceSql varchar(8000),@StrSeprate varchar(10))returns @tem...
今天写到的一个函数
create function [dbo].[split]
(
@SourceSql varchar(8000),
@StrSeprate varchar(10)
)
returns @temp table(F1 varchar(100))
as
begin
declare @i int
set @SourceSql = rtrim(ltrim(@SourceSql))
set @i = charindex(@StrSeprate,@SourceSql)
while @i >= 1
begin
if len(left(@SourceSql,@i-1))>0
begin
insert @temp values(left(@SourceSql,@i-1))
end
set @SourceSql=substring(@SourceSql,@i+1,len(@SourceSql)-@i)
set @i=charindex(@StrSeprate,@SourceSql)
end
if @SourceSql <> ''
insert @temp values(@SourceSql)
return
end
使用实例
ALTER PROC [dbo].[GetTaskData](
@userorgroup NVARCHAR(50))
AS
SELECT
WorkflowNameUrl,
FormId,
WorkflowType,
CreateBy,
CreateTime,
LasttimeInquisitor,
LasttimeProcessTime,
State,
NextInquisitor From Table_Task
WHERE EXISTS(SELECT F1 FROM split(NextInquisitorEn,';') WHERE F1=@userorgroup)