我有一个包含类别值的列,比如
11,2,3
114,3,2
etc.我想从这些唯一的数字中选择顶级类别。我尝试过选择第11类:
select *
from product
where category like '%11%'但这一个选择了机器人11和114。我如何才能只选择11?
发布于 2016-08-16 21:56:05
Declare @Search varchar(25) = '11'
Select * from product where category+',' like '%'+@Search+',%'发布于 2016-08-16 21:56:46
DECLARE @x VARCHAR(MAX) = '11,2,3 114,3,2'
SELECT 1
WHERE ',' + @x + ',' LIKE '%,11,%'发布于 2016-08-16 22:01:37
你可以用基于集合的方法来做,这比更大的集合更快..Using one of the functions from here..
declare @x='11,2,3 114,3,2'
;With cte
as
(select * from dbo.substring_numbers(@x,',')
)
select * from cte where item=11https://stackoverflow.com/questions/38976781
复制相似问题