以下腳本循環遍歷結果集並顯示每條記錄兩次,請告知這是什麼原因。如果在WHERE子句中,transaction_date未被註釋,則結果returend是白天並且是corrcet,transaaction_date被註釋掉以執行滿載加載而不管日期,這是返回雙結果集時的情況。正在返回SQL雙結果集
謝謝您的幫助
/* Sales by Customer
*/
/*
Variables Declared
*/
DECLARE @Loaddate DATETIME
DECLARE @Branch_no TINYINT
/*
Set Variables
*/
SET @branch_no = 0
WHILE @branch_no < 1
BEGIN
SET @Branch_no = @branch_no + 1
SET @Loaddate = (SELECT last_txn_date FROM wf_cntl_details w
WHERE w.depot_no = @Branch_no
AND tbl_name = 'Invoice_Header')
SELECT h.depot_no,h.customer_code,h.transaction_date,h.transaction_no
FROM ft_inv_hdr_sales h
INNER JOIN ft_Inv_dtl_sales d ON
h.depot_no = d.depot_no AND h.transaction_date = d.transaction_date AND
h.transaction_no = d.transaction_no
WHERE d.depot_no = @Branch_no -- and h.transaction_date = @Loaddate
GROUP BY h.depot_no,h.customer_code,h.transaction_date,h.transaction_no
END
首先測試您的查詢,併爲您的變量測試硬編碼值,而不使用while循環。您可能不會加入所有必要字段的表格。 – JeffO