test test
test test

Reputation: 21

How to deduct from only one row?

Let say I have 3 rows that have the same customer id Invoice_CustomerName. However, I only want to deduct the no. of appointment Invoice_TotalAppointment which is only from the first row. My query below will deduct 1 appointment for every row that has the same customer id.

UPDATE InvoiceNew SET Invoice_TotalAppointment = Invoice_TotalAppointment - 1
                    WHERE Invoice_CustomerName = @Appointment_ContactID

How can I deduct only for the first row?

Upvotes: 0

Views: 30

Answers (1)

test test
test test

Reputation: 21

Managed to solve my question :)

UPDATE InvoiceNew SET Invoice_TotalAppointment = Invoice_TotalAppointment - 1
           WHERE Invoice_ID = (SELECT MIN(Invoice_ID) FROM InvoiceNew 
                      WHERE Invoice_CustomerName = @Appointment_ContactID 
                      AND (IsDelete = 0 OR IsDelete = NULL)
                      AND (Invoice_TotalAppointment != 0))

Upvotes: 1

Related Questions