---Insercion de columna 'alquiler_numero' en  'equ_alquiler'


declare @p_idpadre int
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_alquiler' and column_name='alquiler_numero')
begin
alter table [equ_alquiler] add [alquiler_numero] int NOT NULL DEFAULT 0
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_alquiler' and column_name='alquiler_numero';
end


if not exists (select id from doc_tipoDocumento where tipoDocumento= 'Alquiler')
begin
insert into doc_tipoDocumento(eid,uid,tipoDocumento,essalida,mostrarBodega) values ('01',@uid,'Alquiler',0,0)
set @p_idpadre = SCOPE_IDENTITY()
if @p_idpadre<>9 
begin
print 'Atencion: El id para el tipo documento Alquiler no es valido, debe ser 9'
end
else
begin
insert into doc_subtipoDocumento(eid,uid,id_tipodocumento,subtipoDocumento,prefijo,subtipodocumento_codigo) values ('01',@uid,@p_idpadre,'Alquiler','ALQ','ALQ')
end
end

