Sql查询在where子句中接受值

时间:2015-05-10 10:03:31

标签: sql sql-server-2008

我创建了一个名为Invoice的表,在该表中有两列TotalDue和Total balance。根据我的要求,我检索了数据,如( SELECT * FROM Invoice_TBL WHERE IsTableStatus = 1 AND ClientNo = 3 AND TotalBalance> 0 ORDER BY InvoiceNo ASC) 上述查询检索了所选客户的所有总余额。

现在我想做的是"检索所有总余额,接受一张付费发票没有我选择的余额"

SELECT AutoInvoiceNo, InvoiceNo, TotalBalance
FROM Invoice_TBL
WHERE IsTableStatus = 1 AND ClientNo = 3 AND TotalBalance > 0 ;


SELECT AutoInvoiceNo, InvoiceNo, TotalBalance
FROM Invoice_TBL
WHERE IsTableStatus = 1 AND ClientNo = 3 AND AutoInvoiceNo = 5

如何合并上述2个查询并获得一个结果..

请帮帮我.. 感谢...

1 个答案:

答案 0 :(得分:0)

合并where条款:

SELECT AutoInvoiceNo, InvoiceNo, TotalBalance
FROM Invoice_TBL
WHERE IsTableStatus = 1 AND ClientNo = 3 AND (TotalBalance > 0 OR AutoInvoiceNo = 5)