【发布时间】:2012-01-10 15:03:15
【问题描述】:
对不起,我对此有点陌生,所以只是想把所有东西都联系起来。
目前我有一个正常的查询 - SELECT FROM WHERE,它基本上可以找到大约 2000 条记录,我需要更新多个表中的哪个链接。
谁能告诉我如何将这个简单的查询链接到其他东西,这样我基本上可以在同一个脚本中执行多个存储过程?但只影响我的简单查询返回的记录?
抱歉,这听起来可能像泥巴一样清楚!
*编辑 - 更多细节 *
这是我的 Select 查询:
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
因此,使用返回的行,我想执行几个存储过程来更新数据库中我需要的所有内容,这些内容会受到更改这些行的影响。下面是一个存储过程的示例,如果不是更多,我想我需要执行其中的大约 10 个:
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)
【问题讨论】:
标签: sql sql-server