- 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)
- --该片段来自于http://www.codesnippet.cn/detail/1412201514227.html
来源: http://www.codesnippet.cn/detail/1412201514227.html