if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryLogImagenes]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryLogImagenes]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryLogImagenes] @pmIdVehiculo VARCHAR(16),@pmIdConductor VARCHAR(16),@pmIdPropietario VARCHAR(16)=Null
AS
SELECT TipoReg,IdRegistro,ImagenBin,NomArchivo,DescRegistro
FROM LogImagenes
WHERE (TipoReg='VEHICULO' AND (IdRegistro=@pmIdVehiculo OR @pmIdVehiculo IS NULL))
OR ((TipoReg='CONDUCTOR' OR TipoReg='FIRMACDT') AND (IdRegistro=@pmIdConductor OR @pmIdConductor IS NULL))
OR ((TipoReg='TERCERO' OR TipoReg='FIRMAPPT') AND (IdRegistro=@pmIdPropietario OR @pmIdPropietario IS NULL))
GO