3
I have a Stored Procedure
where I need to do a check for a date filter, in case the start date is null I have to do on WHERE
take all records less than the final date, otherwise I make a BETWEEN
between dates.
Example
If initial date is null I do:
select * from tabela where campoTabela <= @datafim
Otherwise:
select * from tabela where data between @dataInicial and @datafim
I tried this way and the performance was very bad, the whole query is a select with 3 sub-selects 3 using Union all I do the variable outside of the first select if it is null executing the query using <= date otherwise do with the between. I made a query only using the first criterion and are returned 30 records, when I applied the second already passed an hour of execution and returned nothing.
– C.Santos
(1) How the column is declared
data
? (2) Table has index by columndata
?– José Diz