如何在MS Access中的表的列中设置文本?

时间:2014-02-20 06:46:44

标签: sql ms-access

我需要在表格栏中显示文字重新比较金额。这是我的访问查询表

enter image description here

现在在新栏目(状态)中,我需要显示

1)如果AmountDue等于GrandTotal或

,则“不支持”

2)如果AmountDue小于GrandTotal或

,则“部分支付”

3)如果AmountDue为零,则“PAID”

我的SQL查询代码是

SELECT InvoiceNumber, 
Terms(Select PaymentTerms from PSD_customerPaymentTerms where PSD_customerPaymentTerms.PTId = NewInvoice_1.Terms) AS Terms, 
InvoiceDate, OurQuote, 
SalesPerson(Select FirstName from Employee where Employee.EmployeeId = NewInvoice_1.SalesPerson) AS SalesPerson, 
CustomerName(Select CustomerName from Customer where Customer.CustomerId = NewInvoice_1.CustomerName) AS CustomerName, 
OrderNumber,  GrandTotal,

(SELECT SUM(PaymentAmount) FROM Payment_Receipt WHERE Payment_Receipt.InvoiceNumber=NewInvoice_1.InvoiceNumber) AS AmountPaid,

GrandTotal - iif(AmountPaid is null, 0, AmountPaid) AS AmountDue
FROM NewInvoice_1;

1 个答案:

答案 0 :(得分:1)

向表中添加新列

ALTER TABLE yourTable ADD COLUMN Status TEXT

然后使用SWITCH函数比较值并更新状态列

UPDATE yourTable 
SET Status = SWITCH(
                    AmountDue = GrandTotal, 'NOT PAID',
                    AmountDue < GrandTotal, 'PARTIALLY PAID',
                    AmountDue = 0 , 'PAID'
                   );