Few Questions..
1. what is the Database u r using?
2. Is that the only statement u r trying to execute, or is there a buch of T-SQL stmnt u r trying to execute?
If the database is SQL server then TOP command might not work, and if it is SQL SERVER then syntax I gave is correct, so if u r having a bunch of statements being excuted then the error might be on previuos lines.
Looking at your query, I noticed you have a semicolon ( at the end. This isn't proper MS SQL Server syntax, so I'm guessing you are using ORACLE or some other SQL platform. If so, you need to post in the proper forum.
If you are using MS SQL Server, Sunil's suggestion should have worked.
The problem with your query is that you didn't tell Microsoft SQL Server WHAT you wanted the TOP 20 of.
Hi,
I followed the suggestion of specifying the db explicitly and it worked. Thanks for that. But I still don't understand why it works for "Select * .." and fails for "Select Top 5 *.." when db is not specied explicitly.
Are you sure you were running the query in the correct database? I run TOP 10 queries quite a bit and they work whether or not I use the USE database command.
But I have at times forgotten to make sure the correct database is being used. That's why I now include the USE command in all my scripts.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.