myLittleTools Community Forum

Welcome Guest Search | Active Topics | Members | Log In | Register

Stored Procedure error Options · View
MattGinn
Posted: Tuesday, March 16, 2010 1:15:44 PM
Rank: Newbie
Groups: Member

Joined: 3/16/2010
Posts: 1
Points: 3
Location: Nottingham
Trying to create this stored procedure using myLittleAdmin. I've cut & pasted the code from the old database (which I could access through enterprise manager) where it worked fine. When I click 'Create' it comes back with an error Incorrect Syntax near 'RS'.

CREATE PROCEDURE sp_Menu#RecursiveSearch
@tempTable varchar(50),
@TopID numeric,
@DepthCount numeric
AS
Declare @MenuOptionID numeric
Declare @ChildrenCount int
Declare @TempDepth numeric
Declare @SQLString varchar(500)
DECLARE RS CURSOR LOCAL FOR
SELECT MenuOptionID FROM tbl_Menu#MenuOptions WHERE ParentMenuOptionID = @TopID

OPEN RS
FETCH NEXT FROM RS INTO @MenuOptionID
WHILE @@FETCH_STATUS = 0
BEGIN
Select @ChildrenCount = Count(*) from tbl_Menu#MenuOptions where ParentMenuOptionID = @MenuOptionID
If @ChildrenCount>0
Begin
SET @SQLString = 'INSERT INTO ##' +@tempTable + ' (MenuOptionID, ChildrenCount, DepthCount) VALUES(' + Cast(@MenuOptionID as varchar(10)) + ', ' + Cast(@ChildrenCount as Varchar(10)) + ',' + Cast(@DepthCount as varchar(10)) + ')'
EXEC (@SQLString)
Set @TempDepth = @DepthCount+1
EXEC sp_Menu#RecursiveSearch @tempTable, @MenuOptionID,@TempDepth
End
Else
Begin
SET @ChildrenCount = 0
SET @SQLString = 'INSERT INTO ##' +@tempTable + ' (MenuOptionID, ChildrenCount, DepthCount) VALUES(' + Cast(@MenuOptionID as varchar(10)) + ', ' + Cast(@ChildrenCount as Varchar(10)) + ',' + Cast(@DepthCount as varchar(10)) + ')'
EXEC (@SQLString)
End
FETCH NEXT FROM RS INTO @MenuOptionID
END
CLOSE RS
DEALLOCATE RS

GO
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

Theme created by myLittleTools
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.