如下 使用2 去查询一个 用逗号分隔开的字段下  有这个id的数据,可以用到数据库的内置函数charindex去查询
select * from Users where charindex(','+'2'+',',','+RoleID+',')>0
 
  列下是  循环得到 数据 字段为逗号分隔的所有数据 放到一个字符串里 
declare @i int
declare @u int
declare @str nvarchar(max)
set @i=1
set @u=(select count(*) from Users)
set @str='';
while @i<=@u
begin
set @str+=(select RoleID from (select ROW_NUMBER() over (order by id) 'rowindex',* from Users)hh where hh.rowindex = @i)+','
set @i=@i+1
end
set @str=SUBSTRING(@str,1,len(@str)-1)
print @str
select * from dbo.fn_Split1(@str,',')
select * from Users where charindex('2',RoleID)>0

相关文章:

  • 2022-12-23
  • 2021-12-09
  • 2021-12-31
  • 2021-06-27
  • 2021-07-10
  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-18
  • 2021-12-19
  • 2021-06-27
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案