I'm new a creating stored procedures and using cursors. For some reason, my cursor does not work. Here is the problem area.
...
DECLARE cPersonnel CURSOR FAST_FORWARD
FOR SELECT personnel_key, login_name, failed_attempts, office_key
FROM Personnel WHERE (disabled = 'N')
set @msg = 'Cursor created'
print @msg
open cPersonnel
set @msg = 'Cursor opened'
print @msg
fetch next from cPersonnel into @p_personnel_key, @p_login_name, @p_level_key, @p_office_key
if (@@fetch_status <> 0)
begin
close Personnel_cursor
set @msg = 'Problem in the first fetch'
print @msg
return
end
While @@fetch_status = 0
set @msg = 'Populating user: ' + @p_login_name
print @msg
begin /* Get the users' Field office info associated with field/area office */
set @f_field_office_key = null
set @g_lmgroup_key = null
set @g_sec_level = null
...
The script stops before the first FETCH (the second print). HELP! I can see why they call this a cursor! >:-<
...
DECLARE cPersonnel CURSOR FAST_FORWARD
FOR SELECT personnel_key, login_name, failed_attempts, office_key
FROM Personnel WHERE (disabled = 'N')
set @msg = 'Cursor created'
print @msg
open cPersonnel
set @msg = 'Cursor opened'
print @msg
fetch next from cPersonnel into @p_personnel_key, @p_login_name, @p_level_key, @p_office_key
if (@@fetch_status <> 0)
begin
close Personnel_cursor
set @msg = 'Problem in the first fetch'
print @msg
return
end
While @@fetch_status = 0
set @msg = 'Populating user: ' + @p_login_name
print @msg
begin /* Get the users' Field office info associated with field/area office */
set @f_field_office_key = null
set @g_lmgroup_key = null
set @g_sec_level = null
...
The script stops before the first FETCH (the second print). HELP! I can see why they call this a cursor! >:-<