lundi 15 juin 2015

How to Create Trigger After Insert with select data from Multiple table with Join in SQlite

I am trying to Create Trigger in SQLite with Select Column data from Join multiple table. But Trigger is not allow me to DECLARE temp variable.

I would like to join 3 table on the bases of newly inserted record in one table and select the data from different table and insert r update in another table (DashboardStatus)

I am getting error [ near "DECLARE": syntax error ]


CREATE TRIGGER triggerDashboard AFTER INSERT ON  LifetouchHeartRate   
BEGIN  
DECLARE @HospitalPatientId   INT;
SET @HospitalPatientId    = SELECT   pd.HospitalPatientId   
FROM  LifetouchHeartRate lthr 
JOIN DeviceSession ds ON ds.DeviceSessionID = lthr.ByDevSessionId
JOIN PatientSession ps ON ps.PatientSessionId = ds.ByPatientSessionId
JOIN PatientDetails pd ON pd.PatientDetailsId = ps.ByPatientId
WHERE lthr.LifeTouchHeartRateID =  new.LifeTouchHeartRateID);
IF @HospitalPatientId   > 0
    BEGIN
                 INSERT OR REPLACE INTO DashboardStatus (LifeTouchHeartRateID, HospitalPatientId)  VALUES (      new.LifeTouchHeartRateID, @HospitalPatientId)
    END
 END

Aucun commentaire:

Enregistrer un commentaire