检测字符串中是否包含指定整数

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
CREATE FUNCTION tmp_f_include
(
    @str_ids varchar(255),
    @id int
)
RETURNS int
AS
BEGIN
 
    declare @p1 int
    declare @p2 int
    set @p1 = 1
 
    set @p2 = charindex(',', @str_ids, @p1)
    while @p2 > 0
    begin
        if ltrim(rtrim(SUBSTRING(@str_ids, @p1, @p2-@p1))) = CAST(@id as varchar(255))
            return 1
        set @p1 = @p2 + 1
        set @p2 = charindex(',', @str_ids, @p1)
    end
    set @p2 = len(@str_ids) + 1
    if ltrim(rtrim(SUBSTRING(@str_ids, @p1, @p2-@p1))) = CAST(@id as varchar(255))
        return 1
    return 0
 
END
 
GO
 
select dbo.tmp_f_include(',,,,51,2,3,4,,,',5)
select dbo.tmp_f_include(',,,,5,2,3,4,,,',5)