if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TercClieCond]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
 CREATE TABLE TercClieCond ( 
IdClie VARCHAR(16) NOT NULL,
Item INT DEFAULT (0) NOT NULL,
DescripCond VARCHAR(3000) NOT NULL
 CONSTRAINT PK_TercClieCond PRIMARY KEY CLUSTERED (IdClie,Item),
 CONSTRAINT CK_TercClieCondIdClie CHECK ((len([IdClie]) > 0)))
ALTER TABLE TercClieCond ADD 
 CONSTRAINT FK_TercClieCond_Terceros FOREIGN KEY (IdClie) REFERENCES [dbo].[Terceros] (IdTercero)
END
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paDelTarifasFletes]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paDelTarifasFletes]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsTarifasFletes]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paInsTarifasFletes]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTarifasFletes]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryTarifasFletes]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTarifasFletesLta]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paQryTarifasFletesLta]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpTarifasFletes]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[paUpTarifasFletes]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TarifasFletes]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TarifasFletes]
GO
CREATE TABLE TarifasFletes ( 
Numero INT DEFAULT (0) NOT NULL,
IdOrigen VARCHAR(8) NOT NULL,
IdDestino VARCHAR(8) NOT NULL,
CdRuta VARCHAR(4) DEFAULT ('0') NOT NULL,
TipoTarifa VARCHAR(10) DEFAULT ('RUTA') NOT NULL,
TarifClie MONEY DEFAULT (0) NOT NULL,
TarifPago MONEY DEFAULT (0) NOT NULL,
TarifTabla MONEY DEFAULT (0) NOT NULL,
IdMneda VARCHAR(5) DEFAULT ('COP') NOT NULL,
UndMed VARCHAR(10) DEFAULT ('0') NOT NULL,
NitCliente VARCHAR(16) DEFAULT ('0') NOT NULL,
CdNat VARCHAR(4),
CdTipoVeh VARCHAR(4),
CdRango VARCHAR(4),
UndTarifClie VARCHAR(10) DEFAULT ('PESO') NOT NULL,
UndTarifPago VARCHAR(10) DEFAULT ('PESO') NOT NULL,
Inactivo BIT DEFAULT (0) NOT NULL,
FechaCrea SMALLDATETIME NOT NULL,
IdUsuario VARCHAR(11) NOT NULL
 CONSTRAINT PK_TarifasFletes PRIMARY KEY CLUSTERED (Numero),
 CONSTRAINT CK_TarifasFletesCdRuta CHECK ((len([CdRuta]) > 0)),
 CONSTRAINT CK_TarifasFletesIdDestino CHECK ((len([IdDestino]) > 0)),
 CONSTRAINT CK_TarifasFletesIdMneda CHECK ((len([IdMneda]) > 0)),
 CONSTRAINT CK_TarifasFletesIdOrigen CHECK ((len([IdOrigen]) > 0)),
 CONSTRAINT CK_TarifasFletesIdUsuario CHECK ((len([IdUsuario]) > 0)),
 CONSTRAINT CK_TarifasFletesNitCliente CHECK ((len([NitCliente]) > 0)),
 CONSTRAINT CK_TarifasFletesTipoTarifa CHECK ((len([TipoTarifa]) > 0)),
 CONSTRAINT CK_TarifasFletesUndMed CHECK ((len([UndMed]) > 0)))
GO
ALTER TABLE TarifasFletes ADD 
 CONSTRAINT FK_TarifasFletes_adm_monedas FOREIGN KEY (IdMneda) REFERENCES [dbo].[adm_monedas] (IdMneda),
 CONSTRAINT FK_TarifasFletes_adm_Usuarios FOREIGN KEY (IdUsuario) REFERENCES [dbo].[adm_Usuarios] (IdUsuario),
 CONSTRAINT FK_TarifasFletes_Localidades FOREIGN KEY (IdOrigen) REFERENCES [dbo].[Localidades] (IdLocal),
 CONSTRAINT FK_TarifasFletes_Localidades1 FOREIGN KEY (IdDestino) REFERENCES [dbo].[Localidades] (IdLocal)
 CREATE NONCLUSTERED INDEX IX_TarifasFletesNitCliente ON TarifasFletes(NitCliente)
 CREATE NONCLUSTERED INDEX IX_TarifasFletesIdOrigen ON TarifasFletes(IdOrigen,IdDestino)