CREATE TABLE ClaseDocCond ( 
IdDoc VARCHAR(4) NOT NULL,
Documento VARCHAR(150) NOT NULL,
Vigencia BIT DEFAULT ((0)) NOT NULL,
Inactivo BIT DEFAULT ((0)) NOT NULL
 CONSTRAINT PK_ClaseDocCond PRIMARY KEY CLUSTERED (IdDoc),
 CONSTRAINT CK_ClaseDocCondDocumento CHECK ((len([Documento])>(0))),
 CONSTRAINT CK_ClaseDocCondIdDoc CHECK ((len([IdDoc])>(0))))
GO
CREATE TABLE TercCndDoc ( 
IdConductor VARCHAR(16) NOT NULL,
Item INT DEFAULT ((0)) NOT NULL,
IdDoc VARCHAR(4) NOT NULL,
Fecha SMALLDATETIME,
FecVence SMALLDATETIME,
Radicado BIT DEFAULT ((0)) NOT NULL,
Descripcion VARCHAR(250)
 CONSTRAINT PK_TercCndDoc PRIMARY KEY CLUSTERED (IdConductor,Item),
 CONSTRAINT CK_TercCndDocIdConductor CHECK ((len([IdConductor])>(0))),
 CONSTRAINT CK_TercCndDocIdDoc CHECK ((len([IdDoc])>(0))))
GO
ALTER TABLE TercCndDoc ADD 
 CONSTRAINT FK_TercCndDoc_ClaseDocCond FOREIGN KEY (IdDoc) REFERENCES [dbo].[ClaseDocCond] (IdDoc),
 CONSTRAINT FK_TercCndDoc_Terceros FOREIGN KEY (IdConductor) REFERENCES [dbo].[Terceros] (IdTercero)


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsClaseDocCond] @pmIdDoc VARCHAR(4),@pmDocumento VARCHAR(150),@pmVigencia BIT,@pmInactivo BIT
 AS 
 INSERT INTO ClaseDocCond (IdDoc,Documento,Vigencia,Inactivo)
 VALUES (@pmIdDoc,@pmDocumento,@pmVigencia,@pmInactivo)
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpClaseDocCond] @pmIdDoc VARCHAR(4),@pmDocumento VARCHAR(150),@pmVigencia BIT,@pmInactivo BIT
 AS 
 UPDATE ClaseDocCond SET Documento=@pmDocumento,Vigencia=@pmVigencia,Inactivo=@pmInactivo
 WHERE IdDoc=@pmIdDoc
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryClaseDocCond] @pmIdDoc VARCHAR(4)
 AS 
 IF @pmIdDoc IS NULL
  BEGIN
   SELECT IdDoc,Documento,Vigencia FROM ClaseDocCond
   WHERE Inactivo=0
  END
 ELSE
  BEGIN
   SELECT IdDoc,Documento,Vigencia,Inactivo FROM ClaseDocCond
   WHERE IdDoc=@pmIdDoc
  END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelClaseDocCond] @pmIdDoc VARCHAR(4)
 AS 
 DELETE FROM ClaseDocCond
 WHERE IdDoc=@pmIdDoc
GO
