SQL - Query in a single table with null values

Asked

Viewed 328 times

1

Hello,

I need to make a date-filtered query. The problem is that non-existent dates in the table need to be returned by the query, having all other fields as Null.

SELECT Data, Servico
FROM controle_equipe
WHERE ((Data >= #4/1/2016#) And (Data <= #5/2/2016#));

The big leap is to need to return all the dates of the selection criteria, even if they are not contained in the controle_team table. I’ve tried using IIF, CASE, but to no avail

  • 1

    To bring in the nulls, all it takes is one WHERE data IS NULL OR ( ... condições ... ) - As for the dates, you can use data BETWEEN( data1, data2 ) to make the two comparisons at once. Anyway, date stored in the order of the question will always give problem. In its format, 4/2/2006 will be within the range shown.

3 answers

2

See if that works for you:

SELECT Data, Servico
FROM controle_equipe
WHERE ((Data >= #4/1/2016#) And (Data <= #5/2/2016#)) OR Data Is Null;

0

I’m used to MS-SQL but see if this syntax exists and can be applied:

 SELECT Data, Servico FROM controle_equipe
 WHERE (Data >= '4/1/2016') And (Data <= '5/2/2016'))
 AND IsNull(Data,1) <> 1

0

From what I understand you need to have another table with all dates type TCALENDARIO, there is only, in the clause where, place controle_equipe.data = TCALENDARIO.data (+)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.