以下脚本循环遍历结果集并显示每条记录两次,请告知是什么原因造成的。如果在 WHERE 子句中未注释 transaction_date,则返回的结果是针对 day 并且是正确的,则无论日期如何,都会将 transaaction_date 注释掉以进行完全加载,这是返回双精度结果集的时间。
谢谢您的帮助
/* 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