select ProductsID
from NetTrade2_Products
where patindex(',%'+rtrim(ProductsCategoriesID)+',%',','+@categoryId+',')>0
from NetTrade2_Products
where patindex(',%'+rtrim(ProductsCategoriesID)+',%',','+@categoryId+',')>0
解决方案 »
- VS2008自带的sql server2005无法开启全文索引
- 找工作者可以进来看看啦!看看啦!
- 如何将getDate()转换成2007-2-2这种形式啊?
- 路过的不要错过,一个存储过程问题,大家请帮帮忙 :-P
- 如何把323-726-1741转换为(323) 726-1741????
- 现在有没有SQL Server 2005 ENT x64版下载?
- 如何取出datetime类型的月和日
- 求教高效率的分类新闻同时显示的查询
- 如何将“2003 十二月 23 15:09AM ”的SQL6.5的日期格式改为"2003-12-23 15:09:09.250"?
- SS2000中,怎么把一个已设好主键的int列改为其它列有数据加入就自动递增,步长为1?
- 表数据的处理
- 我很 虚心 的再请教条简单的sql语句
union all
select * from NetTrade2_Products where patindex(',%'+rtrim(ProductsCategoriesID)+',%',',5,')>0
--先创建字符串分割函数:
IF OBJECT_ID('DBO.fn_split') IS NOT NULL
DROP FUNCTION fn_split
GOcreate function fn_split
(
@inputstr varchar(8000),
@seprator varchar(10)
)
returns @temp table (id varchar(200))
as
begin
declare @i int
set @inputstr = rtrim(ltrim(@inputstr))
set @i = charindex(@seprator, @inputstr)
while @i >= 1
begin
insert @temp values(left(@inputstr, @i - 1))
set @inputstr = substring(@inputstr, @i + 1, len(@inputstr) - @i)
set @i = charindex(@seprator, @inputstr)
end
if @inputstr <> '\'
insert @temp values(@inputstr)
return
end
--然后:
--测试数据
declare @ta table([id] int,[ids] nvarchar(100))
Insert @ta
select 1,N'11,12,13' union all
select 2,N'32,45' union all
select 3,N'123,55' union all
select 4,N'48,32,564' union all
select 5,N'789,231,55,54' Select distinct a.[id], a.[ids] from @ta a,
(select id from DBO.fn_split('32,13',',')) b -- 查找含 32,13 的记录
where charindex(','+ b.[id] +',' , ','+a.[ids]+',')>0
/*
id ids
1 11,12,13
2 32,45
4 48,32,564
*/