概况:文章类别表: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中,请高手帮忙
文章内容表: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中,请高手帮忙
解决方案 »
- sql08r2 求助
- 初学sql,不懂
- 求一SQL查询语句
- 只有MDF恢复数据库,出现“未能读取并闩锁页 (5:681)(用闩锁类型 SH)”是什么错?
- 关于自定义函数。
- ASP导入文本到ACCESS数据库中的类型转换问题。难题。。在线求助。
- 同一条sql语句,只是将条件换了一下位置,为何查询的结果不同?
- 两个导数据问题(CSV文件,记录特别多)急!!
- 请问如何把一A表中的x列记录,复制到B表的y列呢?
- sql中出版过的database,所有的出版项都删除后,怎还不能删除database呢,怎样才能删除有过出版的database?
- 帮忙写一条update语句
- 难题:加密后的存储过程如何简单发布?
http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281
from Class m, Content n where charindex(',' + ltrim(n.cid) + ',' , ',' + m.ChildID + ',') > 0
如:
Class Table
ID 类别名称 ChildID
1 新闻 2,3
2 国内新闻
3 国际新闻Content TableID 所属类别ID 新闻标题
1 2 国内新闻标题 搜索:请选择大类 请选择小类 请输入文章标题当用户只选择了文章大类,大类ID为1,如何找到该大类下所有小类的文章
在线等........
set @id=1
select b.*
from Class a,Content b
where a.id=@id
and charindex(','+ltrim(b.ID)+',',','+a.ChildID+',')>0
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
数据表: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 & ")现在请各位大侠来解决一下,谢了