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
 Incorrect syntax near the keyword 'End'.

Author  Topic 

Sep410
Posting Yak Master

117 Posts

Posted - 2008-07-22 : 16:38:19
Hi,
I don't know what is wrong with this Cursor. Please help me:create procedure SP_City
as set nocount on
declare @Des as varchar(50)
create table temp(Desci varchar(50))
declare SP_City CURSOR FOR
SELECT TOP 100 PERCENT Description FROM Csms.dbo.tbl_City ORDER BY Description
open SP_City
Fetch next from SP_City
into @Des
While(@@FETCH_Status=0 )
insert Into Temp(Desci) values (@Des)
Fetch next from SP_City into @Des
End
Close SP_City
Deallocate SP_City
Go

Here is an error I get:
Server: Msg 156, Level 15, State 1, Procedure SP_City, Line 13
Incorrect syntax near the keyword 'End'.

Thanks,


Sep

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-07-22 : 16:45:19
The real problem is that you are not simply doing this:


insert into Temp(Desci)
select description
from Cms.dbo.tbl_City
order by description


Another problem might be that you are using a "temporary" table called Temp, when you probably don't need it ....

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

Sep410
Posting Yak Master

117 Posts

Posted - 2008-07-22 : 16:48:50
Thanks Jeff

Sep
Go to Top of Page
   

- Advertisement -