HShbib
HShbib

Reputation: 1841

SQL: Records showing blank during the execution of a query

I am executing a query

Select * 
from Parking 
Where ParkingStartTime <> '08:00:00.0000000' 
  AND ParkingStartTime IS NULL

In return to the execution, the columns names are displayed but there records are not showing.

If I used OR Rather than AND it works. Any idea of why AND is not working?

Regards.

Upvotes: 1

Views: 163

Answers (3)

Martin Smith
Martin Smith

Reputation: 453990

This can never return any results. The 2 conditions are contradictory.

If ParkingStartTime IS NULL then ParkingStartTime <> '08:00:00.0000000' will evaluate to unknown.

True and Unknown evaluates to Unknown under the truth tables for 3 valued logic.

enter image description here

Upvotes: 5

catteralld
catteralld

Reputation: 101

ParkingStartTime cannot be both NULL (unknown) and also be equal to a particular value e.g. 08:00:00.0000000

The query does not return any values because your logic is incorrect.

Upvotes: 0

Jeff S
Jeff S

Reputation: 7484

If ParkingStartTime is null, it can't have a value. This means that any value that meets the first part of the query cannot meet the second part of the query.

You either need just

ParkingStartTime is null

or

ParkingStartTime <> '08:00:00.000000'

Upvotes: 1

Related Questions