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 9234947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:54:35+00:00 2026-06-18T06:54:35+00:00

I have a stored procedure which takes a single parameter containing single value. I

  • 0

I have a stored procedure which takes a single parameter containing single value.
I want to pass a collection of values to the procedure one by one and get the combined result into one table . Is this possible ?

Currently I am using cursor to execute procedure in loop but only result from passing first value in the collection is obtained.

declare @clientid varchar(10)

create table #tmpp(secid varchar(10))
insert into #tmpp values(2319)
insert into #tmpp values(2855)
insert into #tmpp values(1303)


    declare cur CURSOR LOCAL for
        select secid from #tmpp 

    open cur

    fetch next from cur into @seclientid

    while @@FETCH_STATUS = 0 BEGIN



    exec getReportforclient @clientid
        fetch next from cur into @clientid
    END

    close cur
    deallocate cur
    drop table #tmpp

If this is too obfuscated / unclear/ silly, can somebody please provide me an alternative ?
Any help is most appreciated . 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-06-18T06:54:36+00:00Added an answer on June 18, 2026 at 6:54 am

    There probably is a way to this without using cursors, but without taking a look at your stored procedure we can’t help too much on that. You can create a table (temporary or not) that has the same structure that the results of your sp and insert the results into it. Something like this:

    DECLARE @clientid VARCHAR(10)
    
    CREATE TABLE #tmpp(secid VARCHAR(10))
    INSERT INTO #tmpp VALUES(2319)
    INSERT INTO #tmpp VALUES(2855)
    INSERT INTO #tmpp VALUES(1303)
    
    
    CREATE TABLE #Results(col1 INT, col2.... -- create the table that will hold your 
                                             -- results
    
    DECLARE cur CURSOR LOCAL for
    SELECT secid 
    FROM #tmpp 
    
    OPEN cur
    FETCH NEXT FROM cur INTO @seclientid
    WHILE @@FETCH_STATUS = 0 
    BEGIN
        INSERT INTO #Results
        exec getReportforclient @clientid
    
        FETCH NEXT FROM cur INTO @clientid
    END
    
    CLOSE cur
    DEALLOCATE cur
    DROP TABLE #tmpp
    
    SELECT *
    FROM #Results
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure which takes an XML parameter and inserts the data
I have a stored procedure which takes as its parameter a varchar which needs
I have a stored procedure that takes a single parameter of data-type XML. I
I have one Stored Procedure which takes around 2-3 minutes to complete its execution.
I have a stored procedure in my database that takes a table value parameter,
I have one procedure which updates record values, and i want to fire it
If I have a parametrized stored procedure which takes a varchar(10) value and converts
I have a stored procedure which executes another procedure inside it. The second one
I have an Informix stored procedure which takes an int and a smallint as
I have an insert stored procedure which takes many parameters - 2 of them

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.