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
|