Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6594549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:49:33+00:00 2026-05-25T17:49:33+00:00

I am using cursor in a stored procedure and there is no other way

  • 0

I am using cursor in a stored procedure and there is no other way but the cursor.

I have pasted my script here. I want to improve the performance of this cursor.
A little background. Im passing ‘name’ and ‘action’ and cursor is calling different stored procedures in return. I have passed another parameter (ID) in all of those stored procedures. Please improve the performance.

ALTER PROCEDURE dbo.Driver_sp
AS

TRUNCATE TABLE Driver_tbl

INSERT INTO Driver_tbl (ID,Name,Action,vipbatchid,processseq)
SELECT ID,Name,Action,batchid,ProcessSeq
FROM pcis_tbl


DECLARE @name varchar(20),
        @action varchar(20),
        @ID bigint

DECLARE cur CURSOR LOCAL FOR
    SELECT id,name,action FROM Driver_tbl
    ORDER BY processseq

OPEN cur  

FETCH NEXT FROM cur INTO @id, @name,@action

WHILE @@FETCH_STATUS = 0

BEGIN

   if (@name = 'A' and @action = 'Update')  
   BEGIN exec A_sp @ID END 
     else 
     if (@name = 'B' and @action = 'Update') 
     BEGIN exec B_sp @ID END 
       else
       if (@name = 'C' and @action = 'Update')
       BEGIN exec C_sp @ID END 
         else 
         if (@name = 'D' and @action = 'Update') 
         BEGIN exec D_sp @ID END 


fetch next FROM cur INTO @id, @name,@action

END
CLOSE cur
DEALLOCATE cur

Thanks !!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:49:34+00:00Added an answer on May 25, 2026 at 5:49 pm

    Assuming, you’re using TSQL, change CURSOR declaration to

    DECLARE cur CURSOR FAST_FORWARD FOR
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a Cursor in my stored procedure. It works on a database
Is it possible to get ref cursor from oracle stored procedure by using DAAB
We have been using temporary table to store intermediate results in pl/sql Stored procedure.
I'm trying to execute a simple stored procedure with Spring/Hibernate using Annotations. Here are
I have to improve some code where an Oracle stored procedure is called from
I have a stored procedure that will return a list of ids. I want
I am using oracle 11g and have written a stored procedure which stores values
I am using Oracle 11g, and I have a lot of stored procedure code
I have a stored procedure, which returns a cursor. The application passes a parameter
So I'm trying to use a stored procedure via a cursor and callproc() but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.