CREATE DATABASE  IF NOT EXISTS `pruebas_saber` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `pruebas_saber`;
-- MySQL dump 10.13  Distrib 5.7.17, for Win64 (x86_64)
--
-- Host: 127.0.0.1    Database: pruebas_saber
-- ------------------------------------------------------
-- Server version	5.5.5-10.1.28-MariaDB

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Dumping routines for database 'pruebas_saber'
--
/*!50003 DROP PROCEDURE IF EXISTS `dim_tiempo` */;
/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client  = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection  = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
/*!50003 SET sql_mode              = 'NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `dim_tiempo`()
BEGIN

 
delete from DIM_TIEMPO;
 
SELECT '2013-01-01' INTO @fi;
SELECT '2016-12-31' INTO @ff;
 
 
while (@fi <= @ff) DO
 
INSERT INTO dim_tiempo
    (
        sk_tiempo,
        fecha,
        anio,
        trimestre,
        mes,
        semana,
        dia,
        diaSemana,
        ntrimestre,
        nmes,
        mmes3L,
        nsemana,
        ndia,
        ndiasemana
    )
SELECT year(@fi)*10000+month(@fi)*100+day(@fi) as FechaSK,
        (@fi) Fecha,
        year(@fi) Anio,
        quarter(@fi) Trimestre,
        month(@fi) Mes,
        week(@fi) Semana,
        RIGHT(concat('0',day(@fi)),2) Dia,
        weekday(@fi) DiaSemana,
        concat('T',quarter(@fi),'/',year(@fi))NTrimestre,
        monthname(@fi) NMes,
        LEFT(monthname(@fi),3) NMes3L,
        concat('Sem ',week(@fi) ,'/', year(@fi)) NSemana,
        concat(RIGHT(concat('0',day(@fi)),2),' ',monthname(@fi)) NDia,
        dayname(@fi) NDiaSemana;

 
set @fi = DATE_ADD(@fi, INTERVAL 1 DAY);
 
END WHILE;

END ;;
DELIMITER ;
/*!50003 SET sql_mode              = @saved_sql_mode */ ;
/*!50003 SET character_set_client  = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection  = @saved_col_connection */ ;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2018-05-03 19:56:15
