存储过程接收多个值(用分隔符号的字符串参数)的用in查询

alter PROCEDURE proc_GetResumeIDByJobseekerID
    @JobseekerIDs varchar(2000)
AS
BEGIN
    select Resumeid from resumebase
    where jobseekerid in (select Rowvalue from dbo.f_split(@JobseekerIDs, ','))

END

 

表值函数

---------------------------------------------------------------
--实现split功能 的函数
--select * from dbo.f_split('kdkdk,kd,dwe',',')
----------------------------------------------------------------
ALTER function [dbo].[f_split](@SourceSql varchar(max),@StrSeprate varchar(10))
    returns @temp table(Rowvalue varchar(1000))
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
    end 

 

posted on 2010-01-26 12:25  伊伦  阅读(817)  评论(0编辑  收藏  举报

导航