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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:33:40+00:00 2026-05-11T20:33:40+00:00

Attempt to generalize my questions… I want to execute a stored procedure for each

  • 0

Attempt to generalize my questions…
I want to execute a stored procedure for each result returned by a SELECT statement.

Mentally I want to try something like
EXEC myStoredProc (SELECT id FROM sometable WHERE cond = @param)

More details related to my specific case…
I have a SaaS application. I would like to delete a tenant from the system. Before I can delete the tenant I must delete all records in the database associated with that tenant.

Tenants own items such as Forms which contain many different types of Fields. I already have a stored proc that deletes a Form and all of its associated items (like Fields). For maintenance reasons (Ie. not wanted to duplicate the logic that determines dependances and associations between records and a form) I’d like to just call that StoredProc for each Form that belongs to a Tenant.

I can retrieve the list of forms by running a query like…
Select formId FROM Forms WHERE Tenant = @TenantId

What I want to do with the result of that query is EXEC my Delete_Form stored procedure.

How can I do this?

  • 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-11T20:33:40+00:00Added an answer on May 11, 2026 at 8:33 pm

    In the case where you don’t have control of the foreign keys and can’t do cascade deletes, you could create a cursor to loop thru and execute the stored proc for each.

    declare @formID int
    declare FormsCursor cursor fast_forward for Select formId FROM Forms WHERE Tenant = @Tenant
    
    open FormsCursor
    
    fetch next from FormsCursor into @formID
    
    while @@fetch_status = 0
    begin
    
       exec Delete_Form @formID
    
       fetch next from FormsCursor into @formID
    
    end
    
    close FormsCursor
    deallocate FormsCursor
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following is my attempt at a prepare statement. It is causing the page
This is an attempt to rephrase my previous question as a result of the
In attempt to learn Hadoop, I am practicing unsolved programming questions from the book
This is my first attempt at a JOIN MySQL statement... I have 2 tables..
My attempt: <xsl:template name=GetDisplay> <xsl:param name=input/> <xsl:text>|</xsl:text> <xsl:call-template name=GetDisplay_1> <xsl:with-param name=input select=$input/> </xsl:call-template> <xsl:text>
I'm trying to attempt something that seems super simple, but right now I want
First attempt to use this cool site - after searching for 2 hours: So
My attempt to customize the method contains of ArrayList, I used Eclipse to generate
I attempt to use webservice return POCO class generated from entity data model as
In an attempt to achieve git nirvana, I'm spending the day learning how to

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.