--guardar datos en temporal
IF EXISTS(SELECT * FROM tempdb..sysobjects WHERE NAME LIKE '#tempTarifas%') 
 DROP TABLE #tempTarifas
 CREATE TABLE #tempTarifas (tmId INT PRIMARY KEY IDENTITY (1,1)
 ,TAR_ORI VARCHAR(8),TAR_DES VARCHAR(8),TAR_UNI VARCHAR(3),TAR_TVH VARCHAR(3),TAR_RAN VARCHAR(3)
,TAR_COS MONEY,TAR_VAL MONEY,TAR_PAG MONEY)
INSERT INTO #tempTarifas (TAR_ORI,TAR_DES,TAR_UNI,TAR_TVH,TAR_RAN,TAR_COS,TAR_VAL,TAR_PAG) 
 SELECT TAR_ORI,TAR_DES,TAR_UNI,TAR_TVH,TAR_RAN,TAR_COS,TAR_VAL,TAR_PAG
 FROM TARIFASFLETES
--reparar tabla
DELETE FROM TARIFASFLETES
DROP TABLE TARIFASFLETES
CREATE TABLE TARIFASFLETES ( 
TAR_NUM INT DEFAULT(0) NOT NULL,
TAR_ORI VARCHAR(8) NOT NULL,
TAR_DES VARCHAR(8) NOT NULL,
TAR_UNI VARCHAR(3) NOT NULL,
TAR_TVH VARCHAR(3) NOT NULL,
TAR_RAN VARCHAR(3) NOT NULL,
TAR_COS MONEY DEFAULT (0) NOT NULL,
TAR_VAL MONEY DEFAULT (0) NOT NULL,
TAR_PAG MONEY DEFAULT (0) NOT NULL,
TAR_RUT VARCHAR(3)
 CONSTRAINT PK_TARIFASFLETES PRIMARY KEY CLUSTERED (TAR_NUM),
 CONSTRAINT CK_TARIFASFLETESTAR_DES CHECK ((len([TAR_DES]) > 0)),
 CONSTRAINT CK_TARIFASFLETESTAR_ORI CHECK ((len([TAR_ORI]) > 0)),
 CONSTRAINT CK_TARIFASFLETESTAR_RAN CHECK ((len([TAR_RAN]) > 0)),
 CONSTRAINT CK_TARIFASFLETESTAR_TVH CHECK ((len([TAR_TVH]) > 0)),
 CONSTRAINT CK_TARIFASFLETESTAR_UNI CHECK ((len([TAR_UNI]) > 0)))
--Importar datos desde el temporal
 DECLARE @TrnNombre VARCHAR(20)
 SET @TrnNombre = 'TrnTarifas'
 BEGIN TRANSACTION @TrnNombre
 DELETE FROM TARIFASFLETES 
 INSERT INTO TARIFASFLETES (TAR_NUM,TAR_ORI,TAR_DES,TAR_UNI,TAR_TVH,TAR_RAN,TAR_COS,TAR_VAL,TAR_PAG,TAR_RUT)
 SELECT tmId,TAR_ORI,TAR_DES,TAR_UNI,TAR_TVH,TAR_RAN,TAR_COS,TAR_VAL,TAR_PAG,'0'
 FROM #tempTarifas
 COMMIT TRANSACTION  @TrnNombre 
 DROP TABLE #tempTarifas