Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select top 1 issue

Author  Topic 

Priya Rajagopalan
Starting Member

10 Posts

Posted - 2005-09-22 : 23:56:11
"Select top 1 * from <tablename>" query is working fine in one database. If execute the same query in another database in the same server, am getting the error " Incorrect Syntax near 1" .Please let me know a solution for this.

Priya

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-23 : 00:20:25
The syntax looks correct
If it works in one database it should definitely work in other database
Make sure you used the same query in other database also

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Priya Rajagopalan
Starting Member

10 Posts

Posted - 2005-09-23 : 01:05:08
I executed the same query withy any change. Both the databases has the table with the same name too.

Priya
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-23 : 01:39:58
Did you execute in a Query Analyser?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Priya Rajagopalan
Starting Member

10 Posts

Posted - 2005-09-23 : 01:50:12
Yes, I executed it in a query analyser.

Priya
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-09-23 : 05:06:31
did you copy and paste or change the database name like

use <dbname>
go

select top 1 * from <tablename>


or did you re-type? sometimes the cause is obvious that it becomes negligible

--------------------
keeping it simple...
Go to Top of Page

Priya Rajagopalan
Starting Member

10 Posts

Posted - 2005-09-23 : 06:06:05
Hi

Tried both the ways. Still facing the same issue. Will there be any issue with the database itself ?
Go to Top of Page

Priya Rajagopalan
Starting Member

10 Posts

Posted - 2005-09-23 : 06:39:25
hi

Issue has been resolved by myself by changing the 'Database compatability level'.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-23 : 06:53:36
What is your 'Database compatability level' when you have that problem?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

supersql
Yak Posting Veteran

99 Posts

Posted - 2005-09-23 : 10:23:42
Priya
Wud u pls let us know, how did u able to resolve. What was the database compatibility level before and to what u changed it.
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2005-09-23 : 10:41:05
She has got the answer and doesn't need any further help ;-)
...So we need to do some analyzing....
As faar as i know TOP will not give any problems with SQL2K and greater!
And since she is new to SQL server it should be immediate prevoius version to SQL2K.
Hence the "server compatibility level" should be - sql 7.0!


------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2005-09-23 : 15:48:34
SELECT TOP 1 is valid in SQL Server 7.0 also, so the compatbility level must have been set at 6.5

If it was actually set that way for a reason, they may be having new problems now...



CODO ERGO SUM
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-09-25 : 22:41:06
thanks for the info guys, something new to learn again for today



--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -