我有一个sp从一个表中选择一些值,还有一个左外连接,连接的条件是选择from和to日期。
我需要根据这两个日期选择数据。
这就是这个角色的样子
SELECT *// all the needed columns
FROM mytable
//other joins
LEFT OUTER JOIN myview ON
//some conditions
myview .soldDate between @fromdate and @todate
选择工作正常,它只选择数据b/w这些日期,但也选择空日期。
如何避免选择这些空值?
2条答案
按热度按时间ulmd4ohb1#
排除联接中没有
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
vaj7vani2#
你可以试着让情况好转
where
而不是on
,因为您正在使用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