我有一個存儲過程調用幾個存儲過程,每個過程將僞數據插入到每個表中。它工作正常,除了在遊標中的每一個循環的單行結果顯示 - 只顯示ClubcardId = 2,ClubcardId = 3等SET NOCOUNT ON和遊標
我已經使用SET NOCOUNT ON,但這似乎沒有幫助。我正在尋找這個存儲過程來創建數百萬行,所以SQL打印每行的結果將是一個問題。
任何人都可以請告知如何防止輸出顯示。我已經複製了下面的父存儲過程。我可以確定顯示屏不是來自儲存proc - lap_CreateClubcardTransaction的子項。
如果我改變:
DECLARE Clubcard_Cursor CURSOR FAST_FORWARD FOR
SELECT ClubcardId FROM Clubcard
...到:
DECLARE Clubcard_Cursor CURSOR FAST_FORWARD FOR
SELECT ClubcardId as 'TEST' FROM Clubcard
...然後我得到的值 'TEST' 顯示光標的每一行。
這裏的父存儲過程:
ALTER PROCEDURE [dbo].[lap_CreateDummyData]
AS
SET NOCOUNT ON
DECLARE @NumberOfCustomers bigint
DECLARE @NumberOfTransactions bigint
SET @NumberOfCustomers = 50000
SET @NumberOfTransactions = 10
EXEC lap_CreateCustomer @NumberOfCustomers = @NumberOfCustomers;
EXEC lap_CreateCustomerPreference @NumberOfCustomers = @NumberOfCustomers;
EXEC lap_CreateClubCard @NumberOfCustomers = @NumberOfCustomers;
EXEC lap_CreateClubCardOffer @NumberOfCustomers = @NumberOfCustomers;
--get static data details to use when creating transaction records
DECLARE @TransactionType tinyint
DECLARE @TransactionReasonID tinyint
DECLARE @TescoStoreID int
DECLARE @PartnerID bigint
DECLARE @PartnerOutletID bigint
DECLARE @ClubcardID bigint
SET @TransactionType = (SELECT TOP 1 TransactionType FROM TransactionType)
SET @TransactionReasonID = (SELECT TOP 1 TransactionReasonID FROM TransactionReason)
SET @TescoStoreID = (SELECT TOP 1 TescoStoreId FROM TescoStore)
SET @PartnerID = (SELECT TOP 1 PartnerID FROM PartnerOutlet)
SET @PartnerOutletID = (SELECT TOP 1 PartnerOutletID FROM PartnerOutlet)
DECLARE Clubcard_Cursor CURSOR FAST_FORWARD FOR
SELECT ClubcardId FROM Clubcard
OPEN Clubcard_Cursor
FETCH NEXT FROM Clubcard_Cursor
INTO @ClubcardID SET NOCOUNT ON
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC lap_CreateClubcardTransaction @NumberOfTransactions = @NumberOfTransactions, @ClubcardID = @ClubcardID, @TransactionType = @TransactionType, @TransactionReasonID = @TransactionReasonID, @TescoStoreId = @TescoStoreID, @PartnerID = @PartnerID, @PartnerOutletID = @PartnerOutletID;
FETCH NEXT FROM Clubcard_Cursor;
END;
CLOSE Clubcard_Cursor;
DEALLOCATE Clubcard_Cursor;
並不想成爲尖刻(好吧,也許不是太尖刻),但如果你將要使用遊標插入數百萬行數據,你將遇到比返回數據更大的問題;你可以改寫proc的邏輯來設置基礎嗎?你的服務器會感謝你:) – 2009-10-07 21:30:39
我沒有使用基於集合的插入,因爲我想要更多地控制我要插入的數據。 – 2009-11-23 17:28:48