Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Related Rants
!Rant .. I need some quick help and didnt know where to go.. so fellow ranters please help...
So I have created an sql trigger which is supposed to add a kill to a doctor whenever one of his patients changes state to "killed" . But I dont know how to just get the one row that is updated. As it looks now : The doctor get patientKilled ++ for every patient he ever had before as well... How can I solve this ?
USE [AD17_Hospital]
GO
/****** Object: Trigger [dbo].[PatientKilled] Script Date: 2017-10-21 19:51:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[PatientKilled] ON [dbo].[Patient]
AFTER UPDATE
AS
BEGIN
declare
SET NOCOUNT ON;
UPDATE Doctor set PatientsKilled+=1
FROM Doctor d
INNER JOIN inserted p
ON d.DoctorId= p.DoctorId
where p.PatientState='Killed'
END
undefined
needed
help
norant
sql