2016-08-24 205 views
0

我有以下SQL语句T-SQL参考查询选择日期

Select * 
from Policies P 
inner join ClientPolicies CP on P.Id = CP.PolicyId 
where p.Id <> 0 
And  P.ProductId = 9 
And  (
    P.PolicyEndDate <= GETDATE() 
or 
    P.PolicyEndDate is null 
    ) 

这拉回所有符合第一policyendate小于GETDATE的值,而不是空值。

+0

标签您正在使用的数据库管理系统。 (例如,GETDATE是产品特定的。) – jarlh

回答

1

更改INNER JOINLEFT JOIN

Select * 
from Policies P 
left join ClientPolicies CP on P.Id = CP.PolicyId 
where p.Id <> 0 
And  P.ProductId = 9 
And  (
    P.PolicyEndDate <= GETDATE() 
or 
    P.PolicyEndDate is null 
    ) 
+0

谢谢您的回答。我知道这是一个快速的问题。 – gilesrpa

+0

不客气。如果有帮助,请不要忘记接受它作为帮助未来提问者的答案。 – RussAwesome