MSSQL の解決策 (意図的に堅牢で、parselist 関数を使用すると、db をより適切なものに正規化できます)
補助機能:
CREATE FUNCTION [dbo].[udf_GetNumeric]
(@strAlphaNumeric VARCHAR(256))
RETURNS VARCHAR(256)
AS
BEGIN
DECLARE @intAlpha INT
SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric)
BEGIN
WHILE @intAlpha > 0
BEGIN
SET @strAlphaNumeric = STUFF(@strAlphaNumeric, @intAlpha, 1, '' )
SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric )
END
END
RETURN ISNULL(@strAlphaNumeric,0)
END
GO
CREATE FUNCTION [dbo].[ParseList_IntAny]
(
@List nvarchar(1000)
)
RETURNS @Result TABLE (
IntValue int not null
)
as
begin
declare @Value nvarchar(20), @Position int
select @List = LTRIM(RTRIM(@List))+ ','
select @Position = CHARINDEX(',', @List, 1)
if REPLACE(@List, ',', '') <> ''
begin
while @Position > 0
begin
select @Value = LTRIM(RTRIM(LEFT(@List, @Position - 1)))
if @Value <> ''
begin
declare @IntValue int
select @IntValue = dbo.udf_GetNumeric(@Value)
insert into @Result(IntValue) values (@IntValue)
end
select @List = RIGHT(@List, LEN(@List) - @Position)
select @Position = CHARINDEX(',', @List, 1)
end
end
return
end
GO
declare @tmp table(ID int, pagename nvarchar(400))
insert into @tmp
select 1,'1'
union select 2,'01'
union select 3,'01, 15'
union select 4,'01, 01 Aaa, 15'
union select 5,'02'
union select 6,'03'
union select 7,'100'
union select 8,'101'
union select 9,'115'
select * from @tmp
where exists(select top 1 1 from dbo.ParseList_IntAny(pagename) where IntValue = 1)