Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Trigger on Table

$
0
0
Hi All, Please can I get some assistance with this trigger. I created the trigger and it's working. However, when I insert a new record in the payment table, it reduces all the patient_accountbalance in the Patient table. I only want it to reduce the amount for the patient that makes a payment.[code="sql"]CREATE TRIGGER [dbo].[PATIENT_ACCTBAL]ON [dbo].[Payment]AFTER INSERTASBEGIN SET NOCOUNT ON;UPDATE PATIENTset Patient_AccountBalance=Patient_AccountBalance - Payment.Payment_AmountFROM PAYMENTwhere PATIENT.Patient_ID=PAYMENT.Patient_IDEND[/code]I have attached the data in my patient table and payment table.

Viewing all articles
Browse latest Browse all 3145

Trending Articles