對不起,我對這個有點新,所以只是想把我的頭連接起來。將簡單查詢鏈接到執行多個存儲過程的腳本
目前我有一個正常的查詢 - SELECT FROM WHERE基本上找到大約2000條記錄,我需要更新哪些鏈接跨越幾個表。
有人能告訴我如何將這個簡單的查詢連接到其他東西,所以我基本上可以執行幾個存儲過程,所有在同一個腳本?但隻影響我的簡單查詢返回的記錄?
道歉,這可能聽起來像泥巴一樣清晰!
*編輯 - 更詳細*
因此,這裏是我的選擇查詢:
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
因此,使用它返回我想給exec一些存儲過程來更新我需要的一切在行數據庫將受到更改這些行的影響。一個存儲過程的下面是一個例子,我想我會需要的,如果不是更多執行有關這些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)
任何幫助的進一步信息還是您需要更多? – shicky 2012-01-10 16:11:00