[英]T-SQL reference selecting dates in a query
我有以下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的值,但不會返回null。
將您的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
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.