Firedragon
New member
- Local time
- Today, 18:46
- Joined
- Apr 20, 2020
- Messages
- 1
I'm here for the first time. I will introduce myself. I'm Dennis and I live in the Netherlands. I used "Google Translate" to be able to put my question clearly in English. Hopefully this isn't a problem? And hopefully I'm in a good place to ask my question?
I have a problem with my trigger on Microsoft SQL Server Version 13. The purpose of this trigger is: When a certain study (MRD or Merus, see my trigger below) is closed, the data may not be changed anymore. Only the 8 columns (Vials_BM_Sample_Code, Vials_BM_Amount, Vials_BM_Cells_Per_Vial, Vials_BM_Comments, Vials_PB_Sample_Code, Vials_PB_Amount, Vials_PB_Cells_Per_Vial, Vials_PB_Comments) in a tbl_def_Patients_Materials table are allowed to be updated.
At the moment my trigger on SQL Server works well if one or more columns of eight columns (see above) are updated via database Microsoft Access 2016. Or if I accidentally update the other columns. If I accidentally update these two groups at the same time, my trigger will no longer work as it should. The trigger should also be able to block everything if these two groups are updated at the same time. I hope I described my problem well?
Thank you very much in advance for your effort to read my problem and I hope you can help me with my problem. Enjoy your day!
Greetings from Dennis.
I have a problem with my trigger on Microsoft SQL Server Version 13. The purpose of this trigger is: When a certain study (MRD or Merus, see my trigger below) is closed, the data may not be changed anymore. Only the 8 columns (Vials_BM_Sample_Code, Vials_BM_Amount, Vials_BM_Cells_Per_Vial, Vials_BM_Comments, Vials_PB_Sample_Code, Vials_PB_Amount, Vials_PB_Cells_Per_Vial, Vials_PB_Comments) in a tbl_def_Patients_Materials table are allowed to be updated.
At the moment my trigger on SQL Server works well if one or more columns of eight columns (see above) are updated via database Microsoft Access 2016. Or if I accidentally update the other columns. If I accidentally update these two groups at the same time, my trigger will no longer work as it should. The trigger should also be able to block everything if these two groups are updated at the same time. I hope I described my problem well?
Thank you very much in advance for your effort to read my problem and I hope you can help me with my problem. Enjoy your day!
Greetings from Dennis.
SQL:
ALTER TRIGGER
trg_completed_studies_2_prevent_update
ON
tbl_def_Patients_Materials
FOR UPDATE
AS
/* The data is partially blocked. */
IF EXISTS (
SELECT
*
FROM
inserted AS ins JOIN tbl_def_Patients AS pat
ON
ins.Patient_ID = pat.Patient_ID
WHERE
/* The MRD group containing the completed studies. */
(
pat.Patient = 'MRD' AND
pat.Study_Name_1 IN (
'HOVON42A',
'HOVON67',
'HOVON81',
'HOVON92',
'HOVON102',
'HOVON103',
'HOVON116'
) AND NOT (
UPDATE(Vials_BM_Sample_Code) OR UPDATE(Vials_BM_Amount) OR UPDATE(Vials_BM_Cells_Per_Vial) OR UPDATE(Vials_BM_Comments) OR
UPDATE(Vials_PB_Sample_Code) OR UPDATE(Vials_PB_Amount) OR UPDATE(Vials_PB_Cells_Per_Vial) OR UPDATE(Vials_PB_Comments)
)
) OR
/* The closed Merus group. */
(
pat.Patient IN (
'Merus'
) AND NOT (
UPDATE(Vials_BM_Sample_Code) OR UPDATE(Vials_BM_Amount) OR UPDATE(Vials_BM_Cells_Per_Vial) OR UPDATE(Vials_BM_Comments) OR
UPDATE(Vials_PB_Sample_Code) OR UPDATE(Vials_PB_Amount) OR UPDATE(Vials_PB_Cells_Per_Vial) OR UPDATE(Vials_PB_Comments)
)
)
)
BEGIN
RAISERROR('Attention! Only the data of vials of completed studies can be updated!', 16, 1)
ROLLBACK TRANSACTION
END
/* The data is completely blocked. */
ELSE IF EXISTS (
SELECT
*
FROM
inserted AS ins JOIN tbl_def_Patients AS pat
ON
ins.Patient_ID = pat.Patient_ID
WHERE
/* The other and closed groups. */
pat.Patient IN (
'JandJ'
)
)
BEGIN
RAISERROR('Attention! The records of completed studies may not be updated!', 16, 1)
ROLLBACK TRANSACTION
END