declare @uid varchar(100)
select @uid=uid from seg_usuario where id=1


if not exists (select * from information_schema.columns where table_name='equ_detalleAlquiler' and column_name='fechaCompromisoDevolucion_ff')
begin
alter table [equ_detalleAlquiler] add [fechaCompromisoDevolucion_ff] smalldatetime DEFAULT 1/1/1900
end
if not exists (select * from _columnas where tabla='equ_detalleAlquiler' and columna='fechaCompromisoDevolucion_ff')
begin
insert into _columnas (tabla,columna,mostrarEnGrilla,ordenGrilla,requerido,tipo,defecto,tamano) select table_name,column_name,1,1,(case is_nullable when 'YES' then 0 else 1 end) as requerido,data_type as tipo, column_default as defecto, character_maximum_length as tamano from INFORMATION_SCHEMA.COLUMNS where table_name='equ_detalleAlquiler' and column_name='fechaCompromisoDevolucion_ff' ;
end
if not exists (select * from [equ_tipoTrazabilidad] where [tipoTrazabilidad]='Alquiler')
begin
INSERT INTO [equ_tipoTrazabilidad]([uid],[eid],[id_usuario_modifico],[id_usuario_creo],[fechaModificacion],[fechaCreacion],[active],[tipoTrazabilidad],[tipoTrazabilidad_codigo])VALUES(@uid,'01',0,0,getDate(),getDate(),1,'Alquiler','')
end
if not exists (select * from _columnas where tabla='equ_detalleAlquiler' and columna='fechaUltimaFactura_fh')
begin
insert into _columnas (tabla,columna,mostrarEnGrilla,ordenGrilla,requerido,tipo,defecto,tamano) select table_name,column_name,1,1,(case is_nullable when 'YES' then 0 else 1 end) as requerido,data_type as tipo, column_default as defecto, character_maximum_length as tamano from INFORMATION_SCHEMA.COLUMNS where table_name='equ_detalleAlquiler' and column_name='fechaUltimaFactura_fh' ;
end
if not exists (select * from _columnas where tabla='equ_detalleAlquiler' and columna='valorMes')
begin
insert into _columnas (tabla,columna,mostrarEnGrilla,ordenGrilla,requerido,tipo,defecto,tamano) select table_name,column_name,1,1,(case is_nullable when 'YES' then 0 else 1 end) as requerido,data_type as tipo, column_default as defecto, character_maximum_length as tamano from INFORMATION_SCHEMA.COLUMNS where table_name='equ_detalleAlquiler' and column_name='valorMes' ;
end
if not exists (select * from _columnas where tabla='equ_detallePagoAlquiler' and columna='valorMulta')
begin
insert into _columnas (tabla,columna,mostrarEnGrilla,ordenGrilla,requerido,tipo,defecto,tamano) select table_name,column_name,1,1,(case is_nullable when 'YES' then 0 else 1 end) as requerido,data_type as tipo, column_default as defecto, character_maximum_length as tamano from INFORMATION_SCHEMA.COLUMNS where table_name='equ_detallePagoAlquiler' and column_name='valorMulta' ;
end
if not exists (select * from _columnas where tabla='equ_detallePagoAlquiler' and columna='facturado')
begin
insert into _columnas (tabla,columna,mostrarEnGrilla,ordenGrilla,requerido,tipo,defecto,tamano) select table_name,column_name,1,1,(case is_nullable when 'YES' then 0 else 1 end) as requerido,data_type as tipo, column_default as defecto, character_maximum_length as tamano from INFORMATION_SCHEMA.COLUMNS where table_name='equ_detallePagoAlquiler' and column_name='facturado' ;
end
if not exists (select * from _columnas where tabla='equ_detallePagoAlquiler' and columna='fechaInicial_ff')
begin
insert into _columnas (tabla,columna,mostrarEnGrilla,ordenGrilla,requerido,tipo,defecto,tamano) select table_name,column_name,1,1,(case is_nullable when 'YES' then 0 else 1 end) as requerido,data_type as tipo, column_default as defecto, character_maximum_length as tamano from INFORMATION_SCHEMA.COLUMNS where table_name='equ_detallePagoAlquiler' and column_name='fechaInicial_ff' ;
end
if not exists (select * from _columnas where tabla='equ_detallePagoAlquiler' and columna='fechaFin_ff')
begin
insert into _columnas (tabla,columna,mostrarEnGrilla,ordenGrilla,requerido,tipo,defecto,tamano) select table_name,column_name,1,1,(case is_nullable when 'YES' then 0 else 1 end) as requerido,data_type as tipo, column_default as defecto, character_maximum_length as tamano from INFORMATION_SCHEMA.COLUMNS where table_name='equ_detallePagoAlquiler' and column_name='fechaFin_ff' ;
end
if not exists (select * from _columnas where tabla='equ_detallePagoAlquiler' and columna='id_documento')
begin
insert into _columnas (tabla,columna,mostrarEnGrilla,ordenGrilla,requerido,tipo,defecto,tamano) select table_name,column_name,1,1,(case is_nullable when 'YES' then 0 else 1 end) as requerido,data_type as tipo, column_default as defecto, character_maximum_length as tamano from INFORMATION_SCHEMA.COLUMNS where table_name='equ_detallePagoAlquiler' and column_name='id_documento' ;
end
