颜色列表id  name
1   红色
2   黑色
3   蓝色
。   。
。   。
。   。
衣服列表
id   colorID   name
1     1        米奇
2     1,2      米奇
3     1,2,3    米奇
4     2,3      米奇
5     2        米奇
现在用repeater显示色系。然后根据点击的色系、在衣服列表里查找含有此色系的衣服。
(假如我点击黑色,查找出来的就应该是衣服列表里的第2、3、4、5条记录。)我已开始想到是like.可是仔细一想不行,然后用in,最后还是有点问题。。
求各位大侠,,指点。。这SQL语句,,怎样才能做到我要的筛选效果呢?

解决方案 »

  1.   

    declare @a varchar(10)
    set @a='2'--黑色
    select * from tb where charindex(','+@a+',',','+ colorID+',')>0
      

  2.   

    下面的方法肯定行用Contains方法: String str = "1,2,3,4,5";//你数据库中查询出的colorID字段
            String temp=","+str+",";
            int i = 2;
            int j = 6; 
            bool b1=str.Contains(","+i+",");//包含2返回true;
            bool b2=str.Contains(","+j+",");//不包含6返回false
            Response.Write(b1+"     "+b2);
      

  3.   


     select * from t1,t2 where t1.Id = t2.colorId and t2.colorId = 2 select * from t2 where colorId in (select Id from t1 where name='黑色')
      

  4.   

    List<string>  colors =  xxx.split(',').ToList();
      

  5.   

    擦,  没看清楚,  就用楼上的Contains方法