set @i = -1; set @sql = repeat(" select 1 union all",-datediff('2021-01-01','2030-12-31')+1); set @sql = left(@sql,length(@sql)-length(" union all")); set @sql = concat("select date_add('2021-01-01',interval @i:=@i+1 day) as date from (",@sql,") as tmp"); prepare stmt from @sql; execute stmt