SQL Incorrect syntax near 错误

简介: 案例分析:在我进行Top数据查询的时候用到如下SQL语句,select top @TopCount * from MD_DataCubeDataDetail2(nolock) Whe...

案例分析:在我进行Top数据查询的时候用到如下SQL语句,

select top @TopCount * from  MD_DataCubeDataDetail2(nolock) 
 Where 1=1  and seqno>=@BeginSeqno and seqno<@EndSeqno and PlanCode=@PlanCode and ReadKey=@ReadKey

运行显示如下错误:

Incorrect syntax near ‘@TopCount’.

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Data.SqlClient.SqlException: Incorrect syntax near ‘@TopCount’.
看来SQL语句有问题,我就一直在寻找,这些参数是有SqlParameter集合提供,如果我直接用数值代替这些参数,则程序能够正确运行,看来的确出自End和start的错误,经过不断的调试,和大胆的推测,最后在参数加入了括号,问题解决啦。SQL语句如下:

select top (@TopCount) * from  MD_DataCubeDataDetail2(nolock) 
 Where 1=1  and seqno>=@BeginSeqno and seqno<@EndSeqno and PlanCode=@PlanCode and ReadKey=@ReadKey

希望以上分享对初学朋友有些帮助,谢谢!
更多关注付义方技术博客:http://blog.csdn.net/fuyifang
或者直接用手机扫描二维码查看更多博文:
付义方CSDN博客二维码

目录
相关文章
|
2月前
|
SQL 关系型数据库 MySQL
解决:Mybatis-plus向数据库插入数据的时候 报You have an error in your SQL syntax
该博客文章讨论了在使用Mybatis-Plus向数据库插入数据时遇到的一个常见问题:SQL语法错误。作者发现错误是由于数据库字段中使用了MySQL的关键字,导致SQL语句执行失败。解决方法是将这些关键字替换为其他字段名称,以避免语法错误。文章通过截图展示了具体的操作步骤。
|
5月前
|
SQL 数据采集 关系型数据库
如何解决MySQL报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL?
如何解决MySQL报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL?
11132 2
|
4月前
|
存储 SQL 关系型数据库
【BUG记录】Cause: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\xA6' for column 'name' at row 1
在MySQL中遇到`Incorrect string value`错误通常是因为尝试插入的字符串包含不被数据库字符集支持的字符,如表情符号。错误根源是MySQL默认的utf8不支持4字节的UTF-8字符(如Emoji)。
142 1
|
3月前
|
SQL 关系型数据库 MySQL
【Python】已解决:ERROR 1064 (42000): You have an error in your SQL syntax. check the manual that correspo
【Python】已解决:ERROR 1064 (42000): You have an error in your SQL syntax. check the manual that correspo
333 0
|
3月前
|
SQL 关系型数据库 MySQL
You have an error in your SQL syntax;check the manual that corresponds to you Mysql server version
You have an error in your SQL syntax;check the manual that corresponds to you Mysql server version
|
4月前
|
SQL 存储 关系型数据库
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
|
4月前
|
SQL 关系型数据库 MySQL
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
|
12月前
|
SQL Java 数据库连接
sql injection violation, syntax error: syntax error, error in :‘**‘expect IDENTIFIER, actual IDENTIF
sql injection violation, syntax error: syntax error, error in :‘**‘expect IDENTIFIER, actual IDENTIF
187 0
|
12月前
|
SQL 关系型数据库 MySQL
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
错误提示: Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; che
117 0
|
5月前
|
SQL 搜索推荐 关系型数据库
Mysql报Cause: java.sql.SQLException: Incorrect string value: ‘\xE5\xA4\x96‘...for column username
Mysql报Cause: java.sql.SQLException: Incorrect string value: ‘\xE5\xA4\x96‘...for column username
42 0
下一篇
无影云桌面