我有一个查询,检查无效发票以及是否重新投标。我们不允许“快速销售”在那里重新招标,因为如果快速销售无效,我的查询就会变得混乱。我想做的是,如果“快速销售”已作废......在重新提交的字段显示“快速销售”中,它也不应该检查发票是否已经重新提交,因为我们不允许这样做。我的查询在下面,我们将搜索 t1.Register_Transaction_Type 列以查看“快速”是否是类型。所有其他交易都很好。
SELECT
t1.Store_Number,
t1.Invoice_Number,
t1.Invoice_Date,
t1.Vehicle_Tag,
t1.Void_Reason,
vt1.Invoice_Total,
t2.Invoice_Number AS [New Invoice #],
t2.Vehicle_Tag AS [Vehicle Tag],
t2.Invoice_Total AS [New Invoice Total],
CASE
WHEN t2.Vehicle_Tag IS NULL THEN 'NO'
WHEN t1.register_transaction_type = 'QUICK' THEN 'Quicksale'
ELSE 'YES'
END AS [Re-tendered?],
User_Tb.User_Name,
t1.Register_Transaction_Type
FROM
Invoice_Tb AS t1
INNER JOIN Employee_Tb
ON t1.Void_Employee_Tax_Payer_Id = Employee_Tb.Tax_Payer_Id
INNER JOIN User_Tb
ON Employee_Tb.User_Id = User_Tb.User_Id
LEFT OUTER JOIN Invoice_Tb AS t2
ON t1.Vehicle_Tag = t2.Vehicle_Tag AND
t2.Void_Flag = 'n' AND
t2.Invoice_Date >= DATEADD(day, DATEDIFF(day, 0, GETDATE()) - 1, 0) AND
t2.Invoice_Date < DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)
WHERE
(t1.Void_Flag = 'y') AND
(t1.Invoice_Date >= DATEADD(day, DATEDIFF(day, 0, GETDATE()) - 1, 0))
AND (t1.Invoice_Date < DATEADD(day, DATEDIFF(day, 0, GETDATE()),0))
AND (t1.Store_Number = '2')
ORDER BY t1.Store_Number, t1.Invoice_Date
下面是我得到的一个例子:你可以看到它只是倾销发票,它没有链接到......
-- ------- --------------------- ------ ------- ------- ------- --------- ----
2 3****** 12/5/2012 12:00:00 AM REFUND 54.9900 3****** 52.9000 Quicksale user
2 3****** 12/5/2012 12:00:00 AM REFUND 54.9900 3****** 59.9800 Quicksale user
2 3****** 12/5/2012 12:00:00 AM REFUND 54.9900 3****** 24.9900 Quicksale user