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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Simple use of TOP keyword

Author  Topic 

kathunter
Starting Member

35 Posts

Posted - 2003-02-25 : 14:30:32
I am using a simple query:

Select top 6 ID from table
order by startdate desc

the query will run the first time, but every other time, gives the error:

>>Server: Msg 170, Level 15, State 1, Line 3
>>Line 3: Incorrect syntax near '6'.

What is going on?

tfountain
Constraint Violating Yak Guru

491 Posts

Posted - 2003-02-25 : 15:27:44
Looks ok to me. By the looks of it, you are executing this through QA. Are you sure you're not highlighting only a portion of the query?

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-02-25 : 15:27:50
Don't see anything wrong syntactially...you're saying you hit execute, and then execute again and it doesn't work? Maybe you accidentally have a char you can't see. Where are you running it from? In Query Analyzer? From an App? If you're setting it to a local variable maybe the set is the problem.

Let me know

Brett

8-)

Go to Top of Page

kathunter
Starting Member

35 Posts

Posted - 2003-02-25 : 15:49:53
I am running it in QA, not highllighting any part of it. I even tried from QA on two different machines, in case it was an isolated application problem

strange.

I should have taken the blue pill
Go to Top of Page

tfountain
Constraint Violating Yak Guru

491 Posts

Posted - 2003-02-25 : 15:57:34
Close QA and reopen. I've experienced flukes similiar to this in the past. It was solved by that.

Go to Top of Page

kathunter
Starting Member

35 Posts

Posted - 2003-02-25 : 19:36:49
I am getting the same error when running in ASP scripts.



quote:

Close QA and reopen. I've experienced flukes similiar to this in the past. It was solved by that.



Go to Top of Page

darinh
Yak Posting Veteran

58 Posts

Posted - 2003-02-25 : 20:18:07
If it is a stored proc try dropping it and typing it in again. I have once puzzled for 3 days over a stored proc that I had originally cut and paste from a website somewhere only to find some invisible formatting character was the problem.

Go to Top of Page
   

- Advertisement -