--Creacion columnas

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_entregable' and column_name = 'nombre' )
begin
alter table [pro_entregable] add [nombre] varchar (100) not NULL DEFAULT 0
end

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_entregable' and column_name = 'producto' )
begin
alter table [pro_entregable] add [producto] varchar (100) not NULL DEFAULT 0
end

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_entregable' and column_name = 'fechaPlaneada' )
begin
alter table [pro_entregable] add [fechaPlaneada] smalldatetime  not NULL DEFAULT 01/01/1900
end

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_entregable' and column_name = 'fechaProyectada' )
begin
alter table [pro_entregable] add [fechaProyectada] smalldatetime  not NULL DEFAULT 01/01/1900
end
if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_entregable' and column_name = 'fechaReal' ) 
begin
alter table [pro_entregable] add [fechaReal] smalldatetime  not NULL DEFAULT 01/01/1900
end
if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_entregable' and column_name = 'esExterno' )
begin
alter table [pro_entregable] add [esExterno] bit  not NULL DEFAULT 1
end
if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_entregable' and column_name = 'porcentajePlaneado' )
begin
alter table [pro_entregable] add [porcentajePlaneado] float not NULL DEFAULT 0
end
if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_entregable' and column_name = 'valorPlaneado' )
begin
alter table [pro_entregable] add [valorPlaneado] int not NULL DEFAULT 0
end

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_entregable' and column_name = 'porcentajeReal' )
begin
alter table [pro_entregable] add [porcentajeReal] float not NULL DEFAULT 0
end
if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_entregable' and column_name = 'valorReal' )
begin
alter table [pro_entregable] add [valorReal] int not NULL DEFAULT 0
end


-- insercion _columnas

IF NOT EXISTS(SELECT *FROM [_columnas] WHERE[tabla]='pro_entregable'
      AND [columna]='nombre' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=5AND[requerido]=1 AND [tipo]='varchar' AND[defecto]=0 AND [tamano] =100)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('pro_entregable' ,'nombre',1 ,5 ,1 ,'varchar' ,0 ,100)
END
IF NOT EXISTS(SELECT *FROM [_columnas] WHERE[tabla]='pro_entregable'
      AND [columna]='producto' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=5AND[requerido]=1 AND [tipo]='varchar' AND[defecto]=0 AND [tamano] =100)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('pro_entregable' ,'producto',1 ,5 ,1 ,'varchar' ,0 ,100)
END

IF NOT EXISTS(SELECT *FROM [_columnas] WHERE[tabla]='pro_entregable'
      AND [columna]='fechaPlaneada' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=5AND[requerido]=1 AND [tipo]='smalldatetime' AND[defecto]=0 AND [tamano] =0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('pro_entregable' ,'fechaPlaneada',1 ,5 ,1 ,'smalldatetime' ,0 ,0)
END
IF NOT EXISTS(SELECT *FROM [_columnas] WHERE[tabla]='pro_entregable'
      AND [columna]='fechaProyectada' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=5AND[requerido]=1 AND [tipo]='smalldatetime' AND[defecto]=0 AND [tamano] =0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('pro_entregable' ,'fechaProyectada',1 ,5 ,1 ,'smalldatetime' ,0 ,0)
END

IF NOT EXISTS(SELECT *FROM [_columnas] WHERE[tabla]='pro_entregable'
      AND [columna]='fechaReal' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=5AND[requerido]=1 AND [tipo]='smalldatetime' AND[defecto]=0 AND [tamano] =0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('pro_entregable' ,'fechaReal',1 ,5 ,1 ,'smalldatetime' ,0 ,0)
END


IF NOT EXISTS(SELECT *FROM [_columnas] WHERE[tabla]='pro_entregable'
      AND [columna]='interno' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=5AND[requerido]=1 AND [tipo]='bit' AND[defecto]=0 AND [tamano] =0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('pro_entregable' ,'interno',1 ,5 ,1 ,'bit' ,0 ,0)
END

IF NOT EXISTS(SELECT *FROM [_columnas] WHERE[tabla]='pro_entregable'
      AND [columna]='porcentajePlaneado' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=5AND[requerido]=1 AND [tipo]='float' AND[defecto]=0 AND [tamano] =0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('pro_entregable' ,'porcentajePlaneado',1 ,5 ,1 ,'float' ,0 ,0)
END

IF NOT EXISTS(SELECT *FROM [_columnas] WHERE[tabla]='pro_entregable'
      AND [columna]='valorPlaneado' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=5AND[requerido]=1 AND [tipo]='int' AND[defecto]=0 AND [tamano] =0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('pro_entregable' ,'valorPlaneado',1 ,5 ,1 ,'int' ,0 ,0)
END


IF NOT EXISTS(SELECT *FROM [_columnas] WHERE[tabla]='pro_entregable'
      AND [columna]='porcentajeReal' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=5AND[requerido]=1 AND [tipo]='float' AND[defecto]=0 AND [tamano] =0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('pro_entregable' ,'porcentajeReal',1 ,5 ,1 ,'float' ,0 ,0)
END

IF NOT EXISTS(SELECT *FROM [_columnas] WHERE[tabla]='pro_entregable'
      AND [columna]='valorReal' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=5AND[requerido]=1 AND [tipo]='int' AND[defecto]=0 AND [tamano] =0)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('pro_entregable' ,'valorReal',1 ,5 ,1 ,'int' ,0 ,0)
END
