Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

225
Views
Cree la tabla de calendario del próximo año utilizando el procedimiento almacenado en MySQL

Necesito crear una tabla de calendario del próximo año usando un procedimiento almacenado en MySQL.

en este código, el problema es establecer el valor del próximo año, porque el resultado es

 Procedure executed successfully Affected rows: 0

No puedo configurar el próximo año en esta parte del código

' @tbl -01-01' + INTERVALO di * 1000 + ci * 100 + ai * 10 + bi DÍA COMO fecha

¿Cómo configuro la variable del próximo año en este procedimiento?

¿alguna idea?

 BEGIN -- create a 2021 year SET @tbl = DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL 1 YEAR),'%Y'); -- create a calendar table 2021 SET @s = CONCAT('DROP TABLE IF EXISTS tbl_calendar_', @tbl); PREPARE stmt FROM @s; EXECUTE stmt; DEALLOCATE PREPARE stmt; SET @s = CONCAT('CREATE TABLE IF NOT EXISTS tbl_calendar_', @tbl, ' LIKE tbl_calendar_2020'); PREPARE stmt FROM @s; EXECUTE stmt; DEALLOCATE PREPARE stmt; -- create a ints table DROP TABLE IF EXISTS ints; CREATE TABLE ints (i INTEGER); INSERT INTO ints VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); -- insert into calendar table 2021 from interval day SET @s = CONCAT('INSERT INTO tbl_calendar_', @tbl, ' SELECT cal.date AS cdate, DAY (cal.date) AS cday, MONTH (cal.date) AS cmonth, YEAR (cal.date) AS cyear, NULL FROM ( SELECT \'`@tbl`-01-01\' + INTERVAL di * 1000 + ci * 100 + ai * 10 + bi DAY AS date FROM ints a JOIN ints b JOIN ints c JOIN ints d ORDER BY di * 1000 + ci * 100 + ai * 10 + bi ) cal WHERE cal.date BETWEEN \'`@tbl`-01-01\' AND \'`@tbl`-12-31\' ORDER BY cal.date ASC;'); PREPARE stmt FROM @s; EXECUTE stmt; DEALLOCATE PREPARE stmt; END
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Podría dividir la cadena en la función concat y tener la variable fuera de la cadena como lo hizo en la cláusula de inserción. Se vería así:

 SET @s = CONCAT('INSERT INTO tbl_calendar_', @tbl, ' SELECT cal.date AS cdate, DAY (cal.date) AS cday, MONTH (cal.date) AS cmonth, YEAR (cal.date) AS cyear, NULL FROM ( SELECT \'', @tbl, '-01-01\' + INTERVAL di * 1000 + ci * 100 + ai * 10 + bi DAY AS date ...'

Deberá dividir la cadena en la función concat de esta manera cada vez que use la variable @tbl en la consulta.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!