IF   :ECB   = 'true' AND   :AllTimeCB    = 'true' AND   :checkBox  = 'true'
	BEGIN
SELECT 
	MachineID,
	PartNumber,
	JobNumber,
	DateTime,
	(case when InspectionResult = 1 then 'PASSED' when InspectionResult = -1 then 'WRONG JOB LOADED' else 'FAILED' end)InspectionResult   , 
	(case when HoleDetection = 1 then 'PASSED'  when HoleDetection = -1 then 'NOT CHECKED' else 'FAILED' end)HoleDetection ,  
	(case when SealDetection = 1 then 'PASSED' else 'FAILED' end)SealDetection ,  
	(case when WeldTrack = 1 then 'PASSED' else 'FAILED' end)WeldTrack ,  
	(case when PartFound = 1 then 'PASSED' else 'FAILED' end)PartFound 
FROM [TransactionGroup].[dbo].[AQVision_Cognex]
	END
IF  :ECB  = 'true' AND   :AllTimeCB  = 'true'
	BEGIN
SELECT 
	MachineID,
	PartNumber,
	JobNumber,
	DateTime,
	(case when InspectionResult = 1 then 'PASSED' when InspectionResult = -1 then 'WRONG JOB LOADED' else 'FAILED' end)InspectionResult   , 
	(case when HoleDetection = 1 then 'PASSED'  when HoleDetection = -1 then 'NOT CHECKED' else 'FAILED' end)HoleDetection ,  
	(case when SealDetection = 1 then 'PASSED' else 'FAILED' end)SealDetection ,  
	(case when WeldTrack = 1 then 'PASSED' else 'FAILED' end)WeldTrack ,  
	(case when PartFound = 1 then 'PASSED' else 'FAILED' end)PartFound 
FROM [TransactionGroup].[dbo].[AQVision_Cognex]
	WHERE PartNumber =  :partNumber 
	END
IF  :checkBox  = 'true' AND    :AllTimeCB   = 'true'
	BEGIN
SELECT 
	MachineID,
	PartNumber,
	JobNumber,
	DateTime,
	(case when InspectionResult = 1 then 'PASSED' when InspectionResult = -1 then 'WRONG JOB LOADED' else 'FAILED' end)InspectionResult   , 
	(case when HoleDetection = 1 then 'PASSED'  when HoleDetection = -1 then 'NOT CHECKED' else 'FAILED' end)HoleDetection ,  
	(case when SealDetection = 1 then 'PASSED' else 'FAILED' end)SealDetection ,  
	(case when WeldTrack = 1 then 'PASSED' else 'FAILED' end)WeldTrack ,  
	(case when PartFound = 1 then 'PASSED' else 'FAILED' end)PartFound 
FROM [TransactionGroup].[dbo].[AQVision_Cognex]
	WHERE MachineID =  :machineID
	END
IF  :checkBox  = 'true' AND  :ECB   = 'true'
	BEGIN
SELECT 
	MachineID,
	PartNumber,
	JobNumber,
	DateTime,
	(case when InspectionResult = 1 then 'PASSED' when InspectionResult = -1 then 'WRONG JOB LOADED' else 'FAILED' end)InspectionResult   , 
	(case when HoleDetection = 1 then 'PASSED'  when HoleDetection = -1 then 'NOT CHECKED' else 'FAILED' end)HoleDetection ,  
	(case when SealDetection = 1 then 'PASSED' else 'FAILED' end)SealDetection ,  
	(case when WeldTrack = 1 then 'PASSED' else 'FAILED' end)WeldTrack ,  
	(case when PartFound = 1 then 'PASSED' else 'FAILED' end)PartFound 
FROM [TransactionGroup].[dbo].[AQVision_Cognex]
	WHERE  DateTime BETWEEN  :startDate AND  :endDate 
	END
	
	
IF  :checkBox  = 'true'
	BEGIN
SELECT 
	MachineID,
	PartNumber,
	JobNumber,
	DateTime,
	(case when InspectionResult = 1 then 'PASSED' when InspectionResult = -1 then 'WRONG JOB LOADED' else 'FAILED' end)InspectionResult   , 
	(case when HoleDetection = 1 then 'PASSED'  when HoleDetection = -1 then 'NOT CHECKED' else 'FAILED' end)HoleDetection ,  
	(case when SealDetection = 1 then 'PASSED' else 'FAILED' end)SealDetection ,  
	(case when WeldTrack = 1 then 'PASSED' else 'FAILED' end)WeldTrack ,  
	(case when PartFound = 1 then 'PASSED' else 'FAILED' end)PartFound 
FROM [TransactionGroup].[dbo].[AQVision_Cognex]
	WHERE  DateTime BETWEEN  :startDate AND  :endDate 
	AND MachineID =  :machineID
	END
	
	
IF :ECB   = 'true'
	BEGIN
SELECT 
	MachineID,
	PartNumber,
	JobNumber,
	DateTime,
	(case when InspectionResult = 1 then 'PASSED' when InspectionResult = -1 then 'WRONG JOB LOADED' else 'FAILED' end)InspectionResult   , 
	(case when HoleDetection = 1 then 'PASSED'  when HoleDetection = -1 then 'NOT CHECKED' else 'FAILED' end)HoleDetection ,  
	(case when SealDetection = 1 then 'PASSED' else 'FAILED' end)SealDetection ,  
	(case when WeldTrack = 1 then 'PASSED' else 'FAILED' end)WeldTrack ,  
	(case when PartFound = 1 then 'PASSED' else 'FAILED' end)PartFound 
FROM [TransactionGroup].[dbo].[AQVision_Cognex]
	WHERE  DateTime BETWEEN  :startDate AND  :endDate 
	AND PartNumber =  :partNumber 
	END
IF   :AllTimeCB   = 'true'
	BEGIN
SELECT 
	MachineID,
	PartNumber,
	JobNumber,
	DateTime,
	(case when InspectionResult = 1 then 'PASSED' when InspectionResult = -1 then 'WRONG JOB LOADED' else 'FAILED' end)InspectionResult   , 
	(case when HoleDetection = 1 then 'PASSED'  when HoleDetection = -1 then 'NOT CHECKED' else 'FAILED' end)HoleDetection ,  
	(case when SealDetection = 1 then 'PASSED' else 'FAILED' end)SealDetection ,  
	(case when WeldTrack = 1 then 'PASSED' else 'FAILED' end)WeldTrack ,  
	(case when PartFound = 1 then 'PASSED' else 'FAILED' end)PartFound 
FROM [TransactionGroup].[dbo].[AQVision_Cognex]
	WHERE  MachineID =  :machineID
	AND PartNumber =  :partNumber 
	END
ELSE 
	BEGIN
SELECT 
	MachineID,
	PartNumber,
	JobNumber,
	DateTime,
	(case when InspectionResult = 1 then 'PASSED' when InspectionResult = -1 then 'WRONG JOB LOADED' else 'FAILED' end)InspectionResult   , 
	(case when HoleDetection = 1 then 'PASSED'  when HoleDetection = -1 then 'NOT CHECKED' else 'FAILED' end)HoleDetection ,  
	(case when SealDetection = 1 then 'PASSED' else 'FAILED' end)SealDetection ,  
	(case when WeldTrack = 1 then 'PASSED' else 'FAILED' end)WeldTrack ,  
	(case when PartFound = 1 then 'PASSED' else 'FAILED' end)PartFound 
FROM [TransactionGroup].[dbo].[AQVision_Cognex]
	WHERE  DateTime BETWEEN  :startDate   AND    :endDate 
	AND PartNumber =   :partNumber 
	AND MachineID =   :machineID 
	END