Wednesday, March 28, 2012

Help on Stored Procedure

CREATE PROCEDURE CreateMenuItems

@.in_cls_id int


AS
declare ....

DECLARE cursor_name CURSOR FOR
SELECT DISTINCT column1,column1,column3 ...
FROM viewUserPrivileges
WHERE ....
ORDER BY ....

OPEN cursor_name

FETCH NEXT FROM cursor_name
INTO declared local variables

while @.@.FETCH_STATUS <> -1
begin

if <condition>
begin
Print 'null'
insert into table...
Execute CreateMenuItems @.in_cls_id
end
else
insert into table...
Print 'Not null'
FETCH NEXT FROM cls_cursor
INTO declared local variables
End
close cursor_name
deallocate cursor_name

In the above procedure CreateMenuItems
calls itself. Is this possible? If not is there any other way to achieve the same?

Thanks in advance
P.C. VaidyanathanExecute CreateMenuItems @.in_cls_idIf it called itself, you would have an endless loop.

Not a good thing - I would not do it.

J.

No comments:

Post a Comment