我在SQL Server 2016中具有下表:
InvoiceNumber AutoPay PaymentPlan
1234 Disabled Active
5678 Inactive Completed
9123 Never Set Up NULL
3456 Active Cancelled
我正在尝试查找帐户上具有自动转帐或PaymentPlan的每个发票编号。
只要其中一列显示“有效”或“已完成”,我希望我的查询显示该行。
结果:
InvoiceNumber AutoPay PaymentPlan
1234 Disabled Active
5678 Inactive Completed
3456 Active Cancelled
答案 0 :(得分:1)
select * from tablename
where paymentplan IN ('Active','Completed') or autopay IN ('Active','Completed')
答案 1 :(得分:1)
我认为下面的方法会有效
根据您的描述,您需要在查询中满足以下条件
select t.* from t
where AutoPay IN ('Active','Completed') or
PaymentPlan in ('Active', 'Completed')
答案 2 :(得分:1)
我认为这是您所需要的:
SELECT InvoiceNumber
FROM myTable
WHERE AutoPay IN ('Active','Completed') OR PaymentPlan IN ('Active','Completed')
答案 3 :(得分:1)
SELECT *
FROM [Invoice_Table]
WHERE [AutoPay] IN ('Active','Completed') OR [PaymentPlan] IN ('Active','Completed')
ORDER BY [InvoiceNumber]
这就是我要使用的,但我不知道您的表的名称,因此请在FROM行中将其交换出去。
欢呼
答案 4 :(得分:-1)
根据您的评论并假设您不知道确切的描述,您可能需要:
SELECT *
FROM [Invoice_Table]
WHERE
(
AutoPay <> 'Never Set Up'
AND AutoPay NOT LIKE '%Disabled%'
AND AutoPay NOT LIKE '%Inactive%'
)
OR
(
PaymentPlan NOT LIKE '%Cancelled%'
AND PaymentPlan <> 'None'
)