简体   繁体   中英

How to set Text in the Column of the table in MS Access?

I need to show text in table column regrading to comparison of amounts. This is my Access Query table

在此处输入图片说明

Now in new column (Status) I need to show

1) "NOT PAID" if AmountDue is equal to GrandTotal or

2) "PARTIALLY PAID" if AmountDue is less then GrandTotal or

3) "PAID" if AmountDue is zero

My SQL Query code is

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;

Add new column to the table

ALTER TABLE yourTable ADD COLUMN Status TEXT

Then use SWITCH function to compare values and update Status column

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM