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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:59:21+00:00 2026-05-28T01:59:21+00:00

Sorry I’m a bit new to this so just trying to get my head

  • 0

Sorry I’m a bit new to this so just trying to get my head around linking everything up.

At the moment I have a normal query – SELECT FROM WHERE which basically finds about 2000 records that I need to update which link across several tables.

Can someone tell me how I can link this simple query to something else so I can basically execute several stored procedures, all in the same script? But only affecting the records returned by my simple query?

Apologies, that probably sounds as clear as mud!

*EDIT – MORE DETAIL *

So here is my Select query:

SELECT [MembershipTermID]
,[MemberStatusProgKey]
,[StartDate]
,[EndDate]
,[AdditionalDiscount]
,[EntryDateTime]
,[UpdateDateTime]
,[MembershipID]
,[AgentID]
,[PlanVersionID]
,[ForceThroughReference]
,[IsForceThrough]
,[NextTermPrePaid]
,[IsBillingMonthly]
,[CICSMEMBERNUM]
,[CICSHISTORY]
,[TMPSeqNoColumn]
,[LastPaymentDate]
,[PaidToDate]
,[IsIndeterminate]
,DATEDIFF(MONTH, PaidToDate, GETDATE()) as MonthsDifference
,dbo.FullMonthsSeparation (PaidToDate, GETDATE())
FROM [Apollo].[dbo].[MembershipTerm] 
WHERE MemberStatusProgKey='DORMANT' 
AND IsBillingMonthly=1 
AND dbo.FullMonthsSeparation (PaidToDate, GETDATE()) >= 2

So using the rows that this returns I want to exec several stored procedures to update everything I need to in the database which would be affected by changing these rows. An example of one stored procedure is below, I think I will need to execute about 10 of these if not more:

USE [Apollo]
GO
/****** Object:  StoredProcedure [dbo].[spCancellationDetailInsert]    Script Date:       01/10/2012 10:21:50 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/* ************************* INSERT *************************/
/* Auto Generated 11/29/2006 7:28:53 PM by Object Builder */
/* ************************* INSERT *************************/


 ALTER Procedure [dbo].[spCancellationDetailInsert]
@StampUser char (10),
    @CancellationDetailID int,
    @RefundAmount float,
    @OldEndDate datetime,
    @EffectiveDate datetime,
    @CancelDate datetime,
    @ReasonCodeProgKey nvarchar (50)

As



/* insert CancellationDetail record     */
Insert [CancellationDetail]
(
    RefundAmount,
    OldEndDate,
    EffectiveDate,
    CancelDate,
    ReasonCodeProgKey
)
Values
(
    @RefundAmount,
    @OldEndDate,
    @EffectiveDate,
    @CancelDate,
    @ReasonCodeProgKey
)
If @@Error <> 0 GoTo InsertErrorHandler

/* save the key of the new row created by the insert */
Select @CancellationDetailID = Scope_Identity()

/* add audit record  */
Insert CancellationDetailAudit
(StampUser,
StampDateTime,
StampAction,
CancellationDetailID,
RefundAmount,
OldEndDate,
EffectiveDate,
CancelDate,
ReasonCodeProgKey)

Values
(@StampUser ,
GetDate() ,
'I',
@CancellationDetailID,
@RefundAmount,
@OldEndDate,
@EffectiveDate,
@CancelDate,
@ReasonCodeProgKey)

If @@Error <> 0 GoTo AuditInsertErrorHandler

Select
 CancellationDetailID = @CancellationDetailID

Return (0)
InsertErrorHandler:
Raiserror ('SQL Error whilst inserting CancellationDetailrecord: Error Code %d',17,1,@@Error)
With Log
Return  (99)

AuditInsertErrorHandler:
Raiserror ('SQL Error whilst inserting audit record for CancellationDetailInsert: Error Code %d',17,1,@@Error)
With Log
Return  (99)
  • 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-28T01:59:22+00:00Added an answer on May 28, 2026 at 1:59 am

    If you’re asking what I think you are –

    Stored procedures can contain (pretty much) any valid SQL statement. This includes returning multiple results sets, performing multiple updates and calling other stored procedures.

    For example:

    CREATE PROCEDURE usp_Sample AS
    
    SELECT * FROM INFORMATION_SCHEMA.COLUMNS
    SELECT * FROM INFORMATION_SCHEMA.TABLES
    
    UPDATE Users SET Active = 0 WHERE ExpiredDate < GetDate()
    
    SELECT Active, COUNT(*) FROM Users GROUP BY Active
    
    EXEC usp_Sample2
    
    GO
    

    Obviously that’s a rather artificial example, but assuming all the objects existed it’d run perfectly well.

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

Sidebar

Related Questions

Sorry this is basic, but I'm new to Python and Django. I have a
Sorry, I'm new to SVN and I looked around a little for this. How
Sorry, I know this question is easy, but I don't know how to get
Sorry I am very new to open graph and have been having difficulty to
Sorry if this is a noob question, but I have been given the dubious
Sorry for asking this but, I cant found a solution that will get this
Sorry in advance if this not 'SO'-ish enough--- I have a tech writing friend
Sorry if this question is confusing. I have a public static class inside my
Sorry if my explanation of my problem is a bit clumsy. Well, I'm trying
Sorry for this Noobie question, I just can't make either of the following code

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.