T-SQL引用在查询中选择日期

时间:2016-08-24 07:35:22

标签: sql

我有以下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
    )

这会拉回与第一个策略日期匹配的所有值小于getdate但不是空值。

1 个答案:

答案 0 :(得分:1)

将您的INNER JOIN更改为LEFT 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
    )
相关问题