概况:文章类别表:Class;(大小类为一个表)
文章内容表:Content;(文章属性,内容)查询目的:得到大类ID(Cid)后 查出(ChildID)中包含子类ID的所有文章,ChildID存储的数据形式为:12,13,14,15第一次方法:
Search = " where [Cid] in (Select [ChildID] From [Class] where [ID] = " & bigCls & ")"出错:在这一子查询或聚合表达式中,text、ntext 和 image 数据类型无效。
服务器: 消息 306,级别 16,状态 1,行 1
不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符。换成:SearchStr = " where cast([Cid] as varchar) in (Select cast([ChildID] as varchar) From [Class] where [ID] = " & bigCls & ")"找不到数据我要的结果是:
Search = " where [Cid] in (12,13,14,15)" 而12,13,14,15则存储在ChildID中,请高手帮忙

解决方案 »

  1.   

    WHERE CHARINDEX(','+LTRIM(CID)+',',','+CHILDID+',')>0
      

  2.   

    最好给出完整的表结构,测试数据,计算方法和正确结果.发帖注意事项
    http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281
      

  3.   

    SearchStr = " where cast([Cid] as varchar) in (Select cast([ChildID] as varchar(8000)) From [Class] where [ID] = " & bigCls & ")"
      

  4.   

    如果不提供表结构,只能猜测为:from Class m, Content n where charindex(n.cid , m.ChildID) > 0
    from Class m, Content n where charindex(',' + ltrim(n.cid) + ',' , ',' + m.ChildID + ',') > 0
      

  5.   

    SearchStr = " where cast([Cid] as varchar) in (Select cast([ChildID] as varchar(max)) From [Class] where [ID] = " & bigCls & ")"
      

  6.   

    我想实现的是:文章大类和小类在一个表,其中大类别有一个字段【ChildID】存储该类别下包括的子类别,存储形式:1,2,3,4,5;
    如:
    Class Table
    ID  类别名称   ChildID
    1    新闻       2,3
    2    国内新闻
    3    国际新闻Content TableID  所属类别ID     新闻标题
    1      2         国内新闻标题  搜索:请选择大类  请选择小类  请输入文章标题当用户只选择了文章大类,大类ID为1,如何找到该大类下所有小类的文章
    在线等........
      

  7.   

    declare @id int
    set @id=1
    select b.*
    from Class a,Content b
    where a.id=@id
    and charindex(','+ltrim(b.ID)+',',','+a.ChildID+',')>0
      

  8.   


    select m.* , n.*
    from Class m , Content n
    where charindex(',' + ltrim(n.id) + ',' , ',' + m.ChildID + ',') > 0select m.* , n.*
    from Class m , Content n
    where ',' + m.ChildID + ',' like '%,' + ltrim(n.id) + ',%'select m.* , n.*
    from Class m , Content n
    where charindex(',' + ltrim(n.id) + ',' , ',' + m.ChildID + ',') > 0 and m.ID = 1select m.* , n.*
    from Class m , Content n
    where ',' + m.ChildID + ',' like '%,' + ltrim(n.id) + ',%' and m.ID = 1
      

  9.   

    对的,
    数据表:1、[Channel];2、[Content][Channel]表 存储文章的大小类别,用[deepPath]区分大小类
    [Content]表 存储文章内容,[Cid]则是文章所属类别ID
    [Channel] 数据:ID   CID   ChildID   deepPath   Name
    1     1     2,3          0      新闻
    2     2                  1      国内新闻
    3     3                  1      国际新闻[Content] 数据:ID   Cid        Title                  Content
    1     3     国家取消学杂费          国家取消学杂费
    前台搜索:请选择大类    请选择小类
       新闻        国内新闻
                   国际新闻问题:
    当用户只选择大类,大类Value值为 1,意思是搜索该大类下所有文章,但在文章内容表中[Cid]为子类别ID,如何搜索ID为1的大类下所有子类别的文章?个人解决方案(不成功):Select * From [Content] where [Cid] in (Select [ChildID] From [Channel] where [ID] = "& bigClsID &")出现以下错误:[Microsoft][ODBC SQL Server Driver][SQL Server]在这一子查询或聚合表达式中,text、ntext 和 image 数据类型无效。 本人第二个解决方法(任不成功):
    Select * From [Content] where cast([Cid] as varchar) in (Select cast([ChildID] as varchar(8000)) From [Channel] where [ID] = " & bigClsID & ")现在请各位大侠来解决一下,谢了