SQLTeam.com | Weblogs | Forums

TSQL Query returning results I am not expecting

Here is my query:
SELECT accession_2.accession_no,
refmd_2.code AS DocCode,
other01.val AS Clinical_History,
other02.val AS NoReturnAddress,
FROM accession_2
WHERE (accession_2.created_date >= '11-1-21') and (accession_2.created_date >= '11-30-21')
OR other02.val IS NOT NULL
OR other03.val IS NOT NULL

data results
Accession_no created_date DocCode CliincalAddress NoReturnAddress No_Provider
12345 2004-12-16 123 PO box 123 Good Address NULL NULL
1278 20014-12-16 453 Po Box 4556 NULL Yes NULL
1238 2021-11-01 352 PO Box 389 NULL NULL NULL
1240 2021-12-15 444 PO Box 555 NULL NULL Yes

The results I want to return are only the rows that are not NULL for every field and between the date range specified in the where clause. I would expection the 3rd row to be gone, but instead it is showing up.

Are the OR's throwing this off? I am getting rows and rows of data in all kinds of data ranges, and the NULL's are being eliminated, but when I change the OR's to AND's I get NO data returned.

Please help me what am I doing wrong?

Your datarange is not correct I think:

(accession_2.created_date >= '11-1-21') and (accession_2.created_date >= '11-30-21')
(accession_2.created_date >= '11-1-21') and (accession_2.created_date <= '11-30-21')

What a bone head mistake! thank you!