samedi 22 février 2020

Find some records of results in other table - SQL

I have this code:

select J.JobID, J.Barcode,J.Bsn, FL.RequirementStatus as OverallResult,S.Name as operation_name, 
FL.Occurred, R.Name as parameter_name,
FL.LowerTorqueLimit, FL.Torque, FL.UpperTorqueLimit,
FL.LowerAngleLimit, FL.Angle, FL.UpperAngleLimit
from FastenerLog FL 
inner join Stations S on FL.StationID=S.StationID
inner join Jobs J on J.JobID = FL.JobID
inner join JobTypes JT on J.JobTypeID=JT.JobTypeID
inner join Requirements R on R.RequirementID=FL.RequirementID
INNER join FastenerStatusEnum FS on FS.FastenerStatus=FL.FastenerStatus
where FL.FastenerStatus=1 and R.Name like '40%'
and FL.Occurred between '02-20-2020 00:00:00' and '02-22-2020 23:59:00'
order by J.Barcode, FL.Occurred desc

It's working good and I'm having this results: https://imgur.com/Re9Dvlo

But I want to add a clause to check in other table when the Barcode of the results has the operation_name T1XX-TR-OP60 (only for the first 9 lines that you can see in the picture).

Pseudocode: IF operation name = T1XX-TR-OP60 then check if Barcode exist in Barcode of Table-X. Because I dont want to show the records if they are not in the Table-X (only for T1XX-TR-OP60).

Note: If operation_name is diferent to T1XX-TR-OP60 nothing will happen for that record, just show like now.

Hope you can help me.

Aucun commentaire:

Enregistrer un commentaire