Today, I found a little issue in Microsoft SQL Server handling the 'TOP' SQL statement when you pass it a number to 'SELECT TOP' by. The code worked in the previous version of MS SQL, before the upgrade.
The error received is "java.sql.SQLException: Incorrect syntax near '@P0'." 'P0' is parameter zero.
For example:
String sqlGetMyData =
"SELECT TOP ? * FROM TEMP_UPLOAD "
+ "WHERE TRANSACTION_TYPE = ? AND TRANSACTION_SUB_TYPE = ? AND TRANSFORMID > ? ORDER BY TRANSFORMID";
The number that 'TOP' uses must be in parenthesis, as detailed below.
String sqlGetMyData =
"SELECT TOP (?) * FROM TEMP_UPLOAD "
+ "WHERE TRANSACTION_TYPE = ? AND TRANSACTION_SUB_TYPE = ? AND TRANSFORMID > ? ORDER BY TRANSFORMID";
Leave a comment