

IF NOT EXISTS(SELECT *FROM [_columnas] WHERE[tabla]='cnt_visitafija' AND [columna]='correoRecordatorio' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=1 AND[requerido]=1 AND [tipo]='varchar' AND [defecto]='' AND [tamano]= 500)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('cnt_visitafija' ,'correoRecordatorio',1 ,1 ,1 ,'varchar' ,'' ,500)
END


if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='cnt_visitafija' and column_name = 'correoRecordatorio' )
begin
alter table [cnt_visitafija] add [correoRecordatorio]  varchar(500)  NOT NULL DEFAULT ''
end


declare @uid as varchar(50)
declare @eid as varchar(50)
declare @id as varchar(50)
select @uid=uid,@eid=eid,@id=id from seg_usuario where id=1

if not exists(select * from gen_enviocorreo where active=1 and enviocorreo_codigo='6_proximaVisita') 
begin 
INSERT INTO [gen_envioCorreo]
           ([uid]
           ,[eid]
           ,[id_usuario_modifico]
           ,[id_usuario_creo]
           ,[fechaModificacion]
           ,[fechaCreacion]
           ,[active]
           ,[envioCorreo]
           ,[envioCorreo_codigo]
           ,[estrategia]
           ,[tabla]
           ,[id_reporte]
           ,[id_subtipoDocumento]
           ,[id_estadoTipoDocumento])
     VALUES
           (@uid
           ,@eid
           ,@id
           ,@id
           ,getdate()
           ,getdate()
           ,1
           ,'proximaVisita'
           ,'6_proximaVisita'
           ,1
           ,'cnt_visitaFija'
           ,0
           ,0
           ,0)
end