ALTER TABLE RegimenDian ADD CodFiscal VARCHAR(20)
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsRegimenDian]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsRegimenDian]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpRegimenDian]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpRegimenDian]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryRegimenDian]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryRegimenDian]
GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsRegimenDian] @pmIdRegimen VARCHAR(4),@pmRegimen VARCHAR(50),@pmCodFiscal VARCHAR(20),@pmInactivo BIT
 AS 
 INSERT INTO RegimenDian (IdRegimen,Regimen,CodFiscal,Inactivo)
 VALUES (@pmIdRegimen,@pmRegimen,@pmCodFiscal,@pmInactivo)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRegimenDian] @pmIdRegimen VARCHAR(4),@pmRegimen VARCHAR(50),@pmCodFiscal VARCHAR(20),@pmInactivo BIT
 AS 
 UPDATE RegimenDian SET Regimen=@pmRegimen,CodFiscal=@pmCodFiscal,Inactivo=@pmInactivo
 WHERE IdRegimen=@pmIdRegimen
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRegimenDian] @pmIdRegimen VARCHAR(4)
 AS 
 IF @pmIdRegimen IS NULL
  SELECT IdRegimen,Regimen,CodFiscal
  FROM RegimenDian
  WHERE Inactivo=0
 ORDER BY Regimen
 ELSE
  SELECT IdRegimen,Regimen,CodFiscal,Inactivo
  FROM RegimenDian
  WHERE IdRegimen=@pmIdRegimen
GO
