The best solution has already been said to you in the comments, if you have a calendar-like interface, simply checking all the days by default as available, and only checking those not available with your query, would be the most optimal.
But if you have some kind of restriction and you have no other way out than to build every day of a certain period, obviously to your query you should add another one to get the additional days. As you mentioned that you do not have all the dates in the table, the implicit problem in your question is:
How to generate a data stream dynamically.
There are multiple possibilities to do this, the one you might think quickly is a WHILE LOOP
and an insertion in a temporary table of all date records from FechaDesde
to FechaHasta
however it is advisable to avoid these cycles for performance issues, other than that there are several options, I recommend reading this article that although it applies to SQL server many tricks could be applied to Informix .
The trick we are going to use is to work with dynamic tables of 10 values that we will "multiply" using CROSS JOIN
a few times to build an incremental sequence of numbers, this number adding it in days to our fechadesde
will give us each one of the dates of the requested period. I attached this Sqlfiddle to SQL Server as an example. Keep in mind that the example manages to "map" up to a maximum of 10,000 days, it can be increased eventually adding more sentences CROSS JOIN
.
In informix it would be more or less like this, bear in mind that for many years I have not seen a Script in this SQL dialect, so I could have made some mistake:
DECLARE v_FechaDesde DATE
DECLARE v_FechaHasta DATE
SELECT v_FechaDesde = '20170101'
SELECT v_FechaHasta = '20170630'
SELECT v_FechaDesde + ((A.A*1000) + (B.A*100) + (C.A*10) + D.A) UNITS DAY
FROM (SELECT 0 AS A UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS A
CROSS JOIN (SELECT 0 AS A UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS B
CROSS JOIN (SELECT 0 AS A UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS C
CROSS JOIN (SELECT 0 AS A UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS D
WHERE v_FechaDesde + ((A.A*1000) + (B.A*100) + (C.A*10) + D.A) UNITS DAY <= v_FechaDesde
ORDER BY 1
What you should do once this sequence is generated is the following:
Filter from the sequence of dates, those that are already in your
consult with a simple NOT IN (<tu consulta>)
Join both queries using a UNION
I hope it's useful for you.