我无法得到内连接的结果

时间:2013-12-16 14:11:24

标签: sql

请我从两个实体(公司合作伙伴和直销代理商)的组合中获得结果,其中我已经指定了列。这两个实体通过查找(直接销售经理)连接到另一个实体,该查询充当过滤器。

这是此处的代码

  SELECT
  Filterednew_corporatepartner.new_cpid AS CorporatePartnerID 
  ,Filterednew_corporatepartner.new_name AS CorporatePartnerName
  ,Filterednew_corporatepartner.new_shortcode_cp AS CorporatePartnerShortcode
  ,Filterednew_directsalesagents.new_agentcode AS DSAAgentcode
  ,Filterednew_directsalesagents.new_name AS DSAName
  ,Filterednew_directsalesmanager.new_name AS DSMName
  ,Filterednew_directsalesmanager.createdon AS CreatedOn
FROM
  Filterednew_directsalesmanager
INNER JOIN Filterednew_directsalesagents
ON Filterednew_directsalesmanager.new_name = Filterednew_directsalesagents.new_directsalesmanagername

INNER JOIN Filterednew_corporatepartner
ON Filterednew_directsalesmanager.new_name  = Filterednew_corporatepartner.new_dsmname


 WHERE (Filterednew_directsalesmanager.createdon >= @StartDate) AND (Filterednew_directsalesmanager.createdon <= @EndDate) AND (Filterednew_directsalesmanager.new_name IN (@DSM))

1 个答案:

答案 0 :(得分:0)

检查Filterednew_directsalesagents和Filterednew_corporatepartner表添加

时有些值为null
WHERE (Filterednew_directsalesmanager.createdon >= @StartDate) AND (Filterednew_directsalesmanager.createdon <= @EndDate) AND (Filterednew_directsalesmanager.new_name IN (@DSM))

这就是为什么你没有得到结果的条件。

我的建议是使用左外连接而不是内连接

更新:点击此链接我正在浏览同样的问题。

How to Calculate From 2 Tables in SQL?