我有一个查询,检查无效发票以及是否重新投标。我们不允许在那里重新招标“quicksales”,如果快速通知无效,我的查询就会变得混乱。我想做的是,如果“快速销售”已经无效......在重新标记的字段显示“QuickSale”中,它也不应该检查发票是否已被重新保留,因为我们不允许它。我的查询在下面,我们将搜索t1.Register_Transaction_Type列以查看“Quick”是否为类型。所有其他交易都很好。
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
答案 0 :(得分:3)
-- code
CASE
WHEN t2.Vehicle_Tag IS NULL THEN 'NO'
WHEN [COLUMN] IS [CONDITION]
-- ...
ELSE 'YES'
END AS [Re-tendered?]
答案 1 :(得分:1)
你要这个吗?
CASE
WHEN t1.Register_Transaction_Type = 'Quick' THEN 'QuickSale'
WHEN t2.Vehicle_Tag IS NULL THEN 'NO'
ELSE 'YES'
END AS [Re-tendered?]
如果您可以提供一个显示您所考虑的逻辑的小表,这可能会有所帮助,即对于列值的这种组合,我想要这种输出值。