ALTER TABLE Trn_NomAjustesCom ADD Orig_Cargue VARCHAR(10)
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryNomNovEst_Cp]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryNomNovEst_Cp]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryNomConCuentasCla]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryNomConCuentasCla]
GO


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomNovEst_Cp] @pmIdPeriodo VARCHAR(8),@pmMes VARCHAR(6),@pmIdEmpleado VARCHAR(16)=Null
AS 
SELECT ET.IdNovedad,N.IdPeriodo,N.IdEmpleado,E.Apellidos,E.Nombres,N.NContrato,N.IdConv,CV.Proyecto,ET.IdEstado,EC.EstadoConv,EC.NColor,ET.FechaDia
FROM Trn_NomNovEst AS ET INNER JOIN  Trn_NomNovConv AS N ON ET.IdNovedad=N.Id
INNER JOIN NomEstadosConv AS EC ON ET.IdEstado=EC.IdEstado
INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado 
INNER JOIN NomConvenciones AS CV ON N.IdConv=CV.Id
WHERE  SUBSTRING(N.IdPeriodo,1,6)=@pmMes AND (N.IdPeriodo=@pmIdPeriodo OR @pmIdPeriodo IS NULL)
AND (N.IdEmpleado=@pmIdEmpleado OR @pmIdEmpleado IS NULL)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomConCuentasCla] @pmIdConcepto VARCHAR(4),@pmNClase INT
,@pmCodNom VARCHAR(4),@pmCodDep VARCHAR(4),@pmTipo_Nom VARCHAR(10)=Null
 AS 
 SELECT IdConcepto,Item,NClase,IdCuenta,TipoMov,CodNom,CodDep,CodFon,NitTerc,Tipo_Nom
 FROM NomConCuentas
 WHERE IdConcepto=@pmIdConcepto AND NClase=@pmNClase
 AND (CodNom=@pmCodNom OR CodNom IS NULL OR LEN(CodNom)=0 )
 AND (CodDep=@pmCodDep OR CodDep IS NULL OR LEN(CodDep)=0)
 AND (ISNULL(Tipo_Nom,'')=@pmTipo_Nom OR @pmTipo_Nom IS NULL OR LEN(ISNULL(Tipo_Nom,''))=0)
 ORDER BY Item
GO
