When running the following code:
| SELECT TOP 10 * FROM table |
You might come across this error:
Server: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near '10'. |
You are either using SQL Server 6.5 or earlier, or your database is in 6.5 compatibility mode.
If you are using 7.0 or greater, you can check by using the following command:
| EXEC sp_dbcmptlevel '<databasename>' |
This will return a result such as:
| The current compatibility level is 65. |
If you would like to change the compatibility level, you can do so as follows:
-- this will make it 7.0 compatible: EXEC sp_dbcmptlevel '<databasename>', 70 -- this will make it 2000 compatible: EXEC sp_dbcmptlevel '<databasename>', 80 |
Another option, assuming you can't just jeopardize existing code and applications by increasing the compatibility level, is to change your code to use ROWCOUNT. The following query is functionally equivalent to SELECT TOP 10 * (though if you have the choice, TOP is more efficient), with the added benefit of being supported in 6.5:
SET ROWCOUNT 10 SELECT * FROM bob SET ROWCOUNT 0 |
Make sure you issue that second ROWCOUNT to remove the row limiter setting; otherwise, this governor could produce some interesting results later on in the code...