日期:2014-05-17  浏览次数:20619 次

全文索引模糊查询+分页存储过程 问题。
     本来在做一个分页的存储。但是我这个查询比较复杂。套用不了一般分页过程

  我的查询语句是:
    select top 5 * from SStand where SStandID not in(select top 3 SStandID from SStand
inner join containstable(SStand,([SStandFRContent],[SStandGRContent]),'安全',50) as k
on SStandID=k.[key]
where SStandTypeID=CONVERT(nvarchar,7)
order by SStandID asc)
  此语句没有语法错误,解释一下
select top 3 SStandID from SStand
inner join containstable(SStand,([SStandFRContent],[SStandGRContent]),'安全',50) as k
on SStandID=k.[key]
where SStandTypeID=CONVERT(nvarchar,7)
order by SStandID asc
 这个查询语句的结果假设为
 id name .....
   1  a
   3  c
   4  d

假如总的查询是:
  id name .....
   1  a
   3  c
   4  d
   5  e
   6  f
   7  g
   8  h
   9  j

 想要得到的结果是:
id name .....
   5  e
   6  f
   7  g
   8  h
   9  j

但是查询总的语句时出现的结果却是
 id  name...
  2    n
  5    e
  6    f
  7    g
  8    h

原因分析:  我这个语句是对的。但就是筛选缺少条件,缺少一个

select * SStandID from SStand
inner join containstable(SStand,([SStandFRContent],[SStandGRContent]),'安全',50) as k
on SStandID=k.[key]
where SStandTypeID=CONVERT(nvarchar,7)
order by SStandID asc
的条件。 not in里面是有一个这样的查询句子,但那个句子只筛选出来了你不要的数据,并没有筛选出来你所要的数据
差上面的那个查询语句,可是我不知道这个语句要放到哪里。 
  
   求解。。。。。

  给个对照:
select top 5 * from SStand where SStandID not in(select top 3 SStandID from SStand where contains(SStandFRContent,'安全')order by SStandID) and Contains(SStandFRContent,'安全')
我缺少的就是这个红色类似的查询语句
------最佳解决方案--------------------
;with cte as (
 select top 8 SStand.*,row_number() over(order by  SStandID asc) as num from SStand
 inner join containstable(SStand,([SStandFRContent],[SStandGRContent]),'安全',50) as k
 on SStandID=k.[key]
 where SStandTypeID=CONVERT(nvarchar,7)
 order by SStandID asc
)
select  * from cte
where num >3

------其他解决方案--------------------

charindex('安全',SStandFRContent)>0

------其他解决方案--------------------
嵌套后加个where条件?用like不行吗?
------其他解决方案--------------------
引用:
SQL code

charindex('安全',SStandFRContent)>0


我的东西都是用我上面的方法做的。 改起来很麻烦。 charindex(....) 这个方法比较古老  我用过。