Sql 不准确显示时的情况

Sql 不准确显示时的情况,sql,sql-server,tsql,sql-server-2012,Sql,Sql Server,Tsql,Sql Server 2012,我试图显示[W-9上传]、[E&O上传]、[License上传]的真值或假值。但结果总是“不”。我永远不会得到一个“是” select distinct tp.License_Exp_Date AS [License Expiration Date], tp.EO_Exp_Date AS [E&O Expiration Date], tp.Insurance_Exp_Date AS [Insurance Expiration Date], tp.Brokerage_Company_Nam

我试图显示[W-9上传]、[E&O上传]、[License上传]的真值或假值。但结果总是“不”。我永远不会得到一个“是”

select distinct tp.License_Exp_Date AS [License Expiration Date],
tp.EO_Exp_Date AS [E&O Expiration Date],
tp.Insurance_Exp_Date AS [Insurance Expiration Date],
tp.Brokerage_Company_Name AS [Agent Company],
pd.agent_id AS [Agent ID],
tp.Other_Phone AS [Agent Phone],
tu.First_Name + ' ' + tu.Last_Name AS [Agent Name],
[W-9 Uploaded] = CASE WHEN tr.User_Id = ta.User_ID and ta.Type_ID = 5 and  ta.Sub_Type_ID = 4 and ta.IsDeleted = 0 THEN 'YES' ELSE 'NO' END,
[E&O Uploaded] = CASE WHEN tr.User_Id = ta.User_ID and ta.Type_ID = 5 and  ta.Sub_Type_ID = 2 and ta.IsDeleted = 0 THEN 'YES' ELSE 'NO' END,
[License Uploaded] = CASE WHEN tp.Real_Estate_Sales_License IS NOT NULL AND LTRIM(RTRIM(Real_Estate_Sales_License)) <> '' AND NameOnLicense IS NOT NULL AND LTRIM(RTRIM(NameOnLicense)) <> ''  AND License_Exp_Date IS NOT NULL AND GETDATE() < License_Exp_Date THEN 'YES' ELSE 'NO' END,
tu.Email AS [Agent Email]
from amp.dbo.tbl_profile tp (nolock)
left join amp.dbo.tbl_user tu (nolock)
    on tp.Resnet_Agent_ID = tu.Resnet_Agent_ID
left join amp.dbo.tbl_Resume tr (nolock)
    on tp.Resnet_Agent_ID= tr.Resnet_Agent_ID
left  join amp.dbo.tbl_Attachment ta (nolock)
on tr.Resume_Id = ta.Business_ID
left join resnet_mysql.dbo.property_details pd
on pd.agent_id = tp.Resnet_Agent_ID
order by [License Expiration Date],[E&O Expiration Date] desc;

tr.user_id=ta.user_id是否适用于这些示例?是的,但当我在该IDI下加入时,它会返回重复的值。如果case语句的条件为真,我想不出任何原因为什么您不会得到“yes”而应该得到“yes”,因此我建议您运行相同的查询(上面的第一个)但是,只需选择相关列(tr.user\u id、ta.user\u id、ta.type\u id等),然后直观地查看它为什么可能不会产生预期的结果。在不查看数据的情况下,没有真正的方法可以帮助您。请将所涉及的每一列添加到
select
tr.User\u ID
ta.User\u ID
,…)中,并使用
where
子句缩小一些示例数据的范围。当您可以看到所有的值时,应该非常清楚。请记住,当您使用
outer
连接时,您需要期望
NULL
值,
为NULL
coalesce
是您的朋友。刚刚注意到
。。。在tr.Resume\u Id=ta.Business\u Id…
上。看起来很奇怪。
select * from amp.dbo.tbl_Attachment

where Type_ID = 5 and Sub_Type_ID =4 and IsDeleted = 0