执行搜索查询,以分页的显示返回
CREATE PROCEDURE GetNewsByTitle
    @KeyWord    varchar(1000),   
    @News_state     int =1,
    @PageSize     int = 10,           -- 页尺寸
    @PageIndex    int = 1 
AS
declare  @strSQL   varchar(1000)     -- 主语句
   set @strSQL = "SELECT TOP "
   +str(@PageSize)+" News_ID,News_title,News_Body,News_addtime,News_editor,News_Summary from News_News  where CHARINDEX(@KeyWord , i.News_title) > 0 and News_state ="

+str(@News_state)+ " and (News_ID not in (select top "+ str((@PageIndex - 1)*@PageSize) + " News_ID from News_News   where CHARINDEX(@KeyWord , i.News_title) > 0 and News_state ="

+str(@News_state)+" ORDER BY News_ID DESC) ) order by  Rank desc "exec (@strSQL)
GO错误为:
以 ' News_ID,News_title,News_Body,News_addtime,News_editor,News_Summary from News_News  where CHARINDEX(@KeyWord , i.News_title) > 0' 开头的 标识符 太长。最大长度为 128。该怎么修改啊?

解决方案 »

  1.   

    1.错误没看出来
    2.其中的i.News_title中的i从哪里来?
    3.你用了not in ,这将会非常的慢,建议优化
      

  2.   

    我加了一个加号,就可以了,可能""中间的字符常量不能在于128长度吧
    ....+ str((@PageIndex - 1)*@PageSize) + " News_ID from News_News   where CHARINDEX(@KeyWord , i.News_title) > 0 and News_state ="

    ....
      

  3.   

    to singlepine(小山):真的没有什么错误,不过把i去掉了
    )+" News_ID,News_title,News_Body,News_addtime,News_editor,News_Summary from 
    换成“* from"
    就可以了,不过感觉不是很舒服ps:当我想获得自定义分页的SQL语句不使用not in怎么实现呢?