Hi,
Here I have wrote an insert query for my table, I want write update query for below coding can you please any one help?
alter trigger trigPatientinformationinsert
on PatientsInformations
for insert,update
as
declare @PatientOutid uniqueidentifier,@Personid uniqueidentifier,@PatientChartNumber nvarchar(250),@PatientID2 nvarchar(250),@LastName nvarchar(250),
@MiddleName nvarchar(250),@FirstName nvarchar(250),@BirthDate datetime,@Sex nvarchar(250),@Patientflag bit,@SignatureOnFile bit,@Street1 nvarchar(250),
@Street2 nvarchar(250),@City nvarchar(250),@State nvarchar(250),@ZipCode nvarchar(250),@Home nvarchar(250),@HomeAddressid nvarchar(250),@stateid nvarchar(250),@Addressid nvarchar(250),@GenderId nvarchar(250),
@Cell nvarchar(250),@CreatedBy uniqueidentifier,@CreatedOn datetime,@ModifiedOn datetime,@ModifiedBy uniqueidentifier
set @PatientOutid=NEWID()
set @Personid=(select Personid from inserted)
set @PatientChartNumber=(select AccountNumber from PatientsInformations where PersonID=@Personid)
set @PatientID2=(select SSN from PersonsInformations where PersonID=@Personid)
set @LastName=(select lastname from PersonsInformations where PersonID=@Personid)
set @MiddleName=(select MiddleName from PersonsInformations where PersonID=@Personid)
set @FirstName=(select FirstName from PersonsInformations where PersonID=@Personid)
set @BirthDate=(select DateOfBirth from PersonsInformations where PersonID=@Personid)
set @GenderId=(select GenderId from PersonsInformations where PersonID=@Personid)
set @sex=(select GenderName from Genders where GenderId=@GenderId)
set @HomeAddressid=(select HomeAddressId from PersonsInformations where PersonID=@Personid)
set @Street1=(select Address1 from Addresses where AddressId=@HomeAddressid)
set @Street2=(select Address2 from Addresses where AddressId=@HomeAddressid)
set @City=(select City from Addresses where AddressId=@HomeAddressid)
set @stateid=(select StateId from Addresses where AddressId=@HomeAddressid)
set @State=(select Statename from States where StateId=@stateid)
set @ZipCode=(select ZipCode from Addresses where AddressId=@HomeAddressid)
set @Home=(select PhoneNo from Addresses where AddressId=@HomeAddressid)
set @Cell=(select CellPhoneNo from PersonsInformations where PersonID=@Personid)
set @CreatedBy=(select CreatedBy from inserted)
set @CreatedOn=(select CreatedOn from inserted)
set @ModifiedOn=(select ModifiedOn from inserted)
set @ModifiedBy=(select ModifiedBy from inserted)
if exists (select Lastname,FirstName,MiddleName,PatinetID2,BirthDate from PatientOutbound)
begin
update PatientOutbound set LastName=@LastName,FirstName=@FirstName,@BirthDate=@BirthDate,Sex=@sex,Street1=@Street1,Street2=@Street2 where personid=@Personid
end
else
insert into PatientOutbound(PatientOutid,Personid,PatientChartNumber,PatientID2,LastName,MiddleName,FirstName,BirthDate,Sex,
Street1,Street2,City,[State],ZipCode,Home,Cell,CreatedBy,CreatedOn,ModifiedOn,ModifiedBy)
values(@PatientOutid,@Personid,@PatientChartNumber,@PatientID2,@LastName,@MiddleName,@FirstName,@BirthDate,
@Sex,@Street1,@Street2,@City,@State,@ZipCode,@Home,@Cell,@CreatedBy,@CreatedOn,@ModifiedOn,@ModifiedBy)
Thanks,