SQL语句

董鲜森 2015-07-13 06:58:19
sql = "select top "+ ps+ " * from t_book where orderBy not in (select top "+ps*(pc-1)+" orderBy from t_book order by orderBy) "+whereSql+" order by orderBy";

其中ps是每页的记录数,pc是当前页码
运行时显示where附近有语法错误
求解答?
...全文
113 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
aidaixinyou 2015-07-14
  • 打赏
  • 举报
回复
把传的where 1=1 换成 and 1=1
aidaixinyou 2015-07-14
  • 打赏
  • 举报
回复
第二个where应该写在第二个查询的括号内吧?你这么写是不是给你算到第一个查询语句里了
许晨旭 2015-07-14
  • 打赏
  • 举报
回复
把你的SQL语句拆分出来就是这样,是传进去的whereSql有问题 应该是 "and 1=1 and"
select top @ps *
from t_book 
where orderBy not in (select top @ps*(@pc-1) orderBy from t_book order by orderBy) 
@whereSql 
order by orderBy
wtujedp 2015-07-14
  • 打赏
  • 举报
回复
跟踪调试一下,看一下,最终的SQL变量里存的SQL语句是怎么样的。另外像whereSql这样的变量前后都加个空格 例whereSql=“ where 1=1 and ”
董鲜森 2015-07-13
  • 打赏
  • 举报
回复
'ps' 附近有语法错误。 Query: select top ps * from t_book where orderBy not in (select top ps*(pc-1) orderBy from t_book order by orderBy) where 1=1 and cid = ? order by orderBy Parameters: [18]
习惯性蹭分 2015-07-13
  • 打赏
  • 举报
回复
可以先把拼接的语句print出来,检查下就知道哪里有问题了。
道玄希言 2015-07-13
  • 打赏
  • 举报
回复
你还是放出最终执行时的语句吧 这语句看不出什么的。
董鲜森 2015-07-13
  • 打赏
  • 举报
回复
其中whereSql是where 1=1 and id=?

22,301

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧