0

I have an Sp to select some values from a table and there is a left outer join, and the condition of the join is to select with respect to from and to dates.

I need to select data b/w these two dates.

this is how the part looks like

SELECT *// all the needed columns
 FROM  mytable            
     //other joins   
     LEFT OUTER JOIN myview ON              
        //some conditions         
        myview .soldDate between @fromdate and @todate    

The selection works fine, it selecting only data b/w those dates, but also selcting null dates.

enter image description here

How do I avoid selecting these null values?

J M
  • 396
  • 6
  • 23

2 Answers2

1

You can try to let condition in where instead of on, because you are using outer join

SELECT *// all the needed columns
 FROM  mytable            
     //other joins   
     LEFT OUTER JOIN myview ON              
        //some conditions         
WHERE 
    myview.soldDate between @fromdate and @todate   

Or just use INNER JOIN instead of LEFT OUTER JOIN

D-Shih
  • 44,943
  • 6
  • 31
  • 51
0

Exclude rows in join that does does not have a soldDate

SELECT * -- all the needed columns
FROM mytable
--other joins
LEFT OUTER JOIN myview ON -- conditions
        (myview.soldDate IS NOT NULL AND myview.soldDate between @fromdate and @todate

Your question doesn't explain why soldDate is NULL. It could be because of LEFT JOIN, but also by design.

If it's the first, just use a INNER JOIN. If it's by design, use my query above.

Kordonme
  • 2,314
  • 3
  • 20
  • 32
  • If no date is selected in the previous form, soldDate is saved as null in the table. – J M Dec 17 '18 at 10:41