您实际上应该重新设计该表,以将这些值从逗号分隔成单独的行中分离出来。但是,如果这不可能,那么您将不得不进行字符串比较:
DECLARE @id INT = 3DECLARE @stringId VARCHAr(50) = CAST(@id AS VARCHAr(50))SELECt * FROM MyTable WHERe categoryIds = @stringId -- When there is only 1 id in the tableOR categoryIds LIKE @stringId + ',%' -- When the id is the first oneOR categoryIds LIKE '%,' + @stringId + ',%' -- When the id is in the middleOR categoryIds LIKE '%,' + @stringId -- When the id is at the end



