2014-02-20 49 views
0

我需要顯示文本在表列中重新調整比較的金額。這是我訪問查詢表如何在MS Access中的表的列中設置文本?

enter image description here

現在,在新列(狀態)我需要顯示

1) 「NOT PAID」 如果AmountDue等於GrandTotal或

2)「部分支付」如果AmountDue是小於GrandTotal或

3) 「PAID」 如果AmountDue爲零

我的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

新列添加到表

ALTER TABLE yourTable ADD COLUMN Status TEXT 

然後用SWITCH功能來比較值,並更新狀態欄

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

是'對於這麼短的值text'真正的最好的數據類型? – ErikE

+0

嗨@mhasan感謝您的回答,上表是查詢表。我如何在Query中添加此代碼? 。我更新了我的問題,請確認。 – Srihari

相關問題