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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:41:41+00:00 2026-05-23T14:41:41+00:00

Consider the table SAMPLE: id integer name nvarchar(10) There is a stored proc called

  • 0

Consider the table SAMPLE:

id       integer
name     nvarchar(10)

There is a stored proc called myproc. It takes only one paramater ( which is id)

Given a name as parameter, find all rows with the name = @nameparameter and pass all those ids
to myproc

eg:

sample->
1   mark
2   mark
3   stu
41  mark

When mark is passed, 1 ,2 and 41 are to be passed to myproc individually.

i.e. the following should happen:

execute myproc 1
execute myproc 2
execute myproc 41

I can’t touch myproc nor see its content. I just have to pass the values to it.

  • 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-23T14:41:41+00:00Added an answer on May 23, 2026 at 2:41 pm

    If you must iterate(*), use the construct designed to do it – the cursor. Much maligned, but if it most clearly expresses your intentions, I say use it:

    DECLARE @ID int
    DECLARE IDs CURSOR LOCAL FOR select ID from SAMPLE where Name = @NameParameter
    
    OPEN IDs
    FETCH NEXT FROM IDs into @ID
    WHILE @@FETCH_STATUS = 0
    BEGIN
        exec myproc @ID
    
        FETCH NEXT FROM IDs into @ID
    END
    
    CLOSE IDs
    DEALLOCATE IDs
    

    (*) This answer has received a few upvotes recently, but I feel I ought to incorporate my original comment here also, and add some general advice:

    In SQL, you should generally seek a set-based solution. The entire language is oriented around set-based solutions, and (in turn) the optimizer is oriented around making set-based solutions work well. In further turn, the tools that we have available for tuning the optimizer is also set-oriented – e.g. applying indexes to tables.

    There are a few situations where iteration is the best approach. These are few are far between, and may be likened to Jackson’s rules on optimization – don’t do it – and (for experts only) don’t do it yet.

    You’re far better served to first try to formulate what you want in terms of the set of all rows to be affected – what is the overall change to be achieved? – and then try to formulate a query that encapsulates that goal. Only if the query produced by doing so is not performing adequately (or there’s some other component that is unable to do anything other than deal with each row individually) should you consider iteration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider the following table create table sample(id, name, numeric, qno, ans1,ans2,ans3) sample data 1,
For my question lets consider the following sample table data: ProductID    ProductName    Price   Category 1                Apple                 5.00       Fruits
Consider a table or CTE structured like this: Name Num ---- ---- Abc 12
Consider the following table: create table temp ( name int, a int, b int
Consider following schema: Customers: Col | Type | -------------------| id | INTEGER | name
Please consider following sample table structure: +-------------------------------+--------------+------+-----+---------+-------+ | Field | Type | Null |
Consider the following HTML table: <table id=myTable1> <tr id=TR1> <td><input type=text id=quantity1 name=quantity1 /></td>
Is there an SQL injection possibility even when using mysql_real_escape_string() function? Consider this sample
Let's consider this table: [name] [type] Ken Anderson 1 John Smith 2 Bill Anderson
Consider a simple table with an auto-increment column like this: CREATE TABLE foo (

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.