日期:2014-05-18  浏览次数:20471 次

超简单问题,求快速解决。。
SQL code

ALTER VIEW [dbo].[V_Idata] AS
SELECT DoradoReport.中文姓,DoradoReport.中文名,DoradoReport.SAP工号,DoradoReport.员工原工号,SAP.employee_ID,notes.PersonID,notes.email,
CTS.cts_ID,RMS_LOGONNAME,Domain_User.user_id
FROM DoradoReport LEFT outer join SAP ON DoradoReport.SAP工号=SAP.employee_ID
                  LEFT outer join notes ON DoradoReport.员工原工号=notes.PersonID or DoradoReport.SAP工号=notes.PersonID
                  LEFT outer join CTS ON DoradoReport.员工原工号=CTS.cts_ID OR DoradoReport.SAP工号=CTS.cts_ID
                  LEFT outer join RMS ON DoradoReport.员工原工号=RMS.RMS_ID OR DoradoReport.SAP工号=RMS.RMS_ID
                  LEFT outer join Domain_User ON DoradoReport.员工原工号=Domain_User.user_id WHERE Domain_User.User_kind='Domain Users'



我以DoradoReport表为中心进行联接,原则上应该是DoradoReport表不变,其他表根据关联主键关联进来构成张大表,但是我关联了最后一行后,行数变成了与Domain_User匹配后的行数,没匹配到的就没出来了,我需要他全部出来,请高手帮忙解决!

------解决方案--------------------
SQL code
ALTER VIEW [dbo].[V_Idata] AS
SELECT DoradoReport.中文姓,DoradoReport.中文名,DoradoReport.SAP工号,DoradoReport.员工原工号,SAP.employee_ID,notes.PersonID,notes.email,
CTS.cts_ID,RMS_LOGONNAME,Domain_User.user_id
FROM DoradoReport LEFT outer join SAP ON DoradoReport.SAP工号=SAP.employee_ID
                  LEFT outer join notes ON DoradoReport.员工原工号=notes.PersonID or DoradoReport.SAP工号=notes.PersonID
                  LEFT outer join CTS ON DoradoReport.员工原工号=CTS.cts_ID OR DoradoReport.SAP工号=CTS.cts_ID
                  LEFT outer join RMS ON DoradoReport.员工原工号=RMS.RMS_ID OR DoradoReport.SAP工号=RMS.RMS_ID
                  LEFT outer join Domain_User ON DoradoReport.员工原工号=Domain_User.user_id and Domain_User.User_kind='Domain Users'

------解决方案--------------------
SQL code
ALTER VIEW [dbo].[V_Idata] AS
SELECT DoradoReport.中文姓,DoradoReport.中文名,DoradoReport.SAP工号,DoradoReport.员工原工号,SAP.employee_ID,notes.PersonID,notes.email,
CTS.cts_ID,RMS_LOGONNAME,Domain_User.user_id
FROM DoradoReport LEFT outer join SAP ON DoradoReport.SAP工号=SAP.employee_ID
                  LEFT outer join notes ON DoradoReport.员工原工号=notes.PersonID or DoradoReport.SAP工号=notes.PersonID
                  LEFT outer join CTS ON DoradoReport.员工原工号=CTS.cts_ID OR DoradoReport.SAP工号=CTS.cts_ID
                  LEFT outer join RMS ON DoradoReport.员工原工号=RMS.RMS_ID OR DoradoReport.SAP工号=RMS.RMS_ID
                  LEFT outer join Domain_User ON DoradoReport.员工原工号=Domain_User.user_id and Domain_User.User_kind='Domain Users'

------解决方案--------------------
...

ALTER VIEW [dbo].[V_Idata] AS
SELECT DoradoReport.中文姓,DoradoReport.中文名,DoradoReport.SAP工号,DoradoReport.员工原工号,SAP.employee_ID,notes.PersonID,notes.email,
CTS.cts_ID,RMS_LOGONNAME,Domain_User.user_id
FROM DoradoReport LEFT outer join SAP ON DoradoReport.SAP工号=SAP.employee_ID
LEFT outer join notes ON DoradoReport.员工原工号=notes.PersonID or DoradoReport.SAP工号=notes.PersonID
LEFT outer join CTS ON DoradoReport.员工原工号=CTS.cts_ID OR DoradoReport.SAP工号=CTS.cts_ID
LEFT outer join RMS ON DoradoReport.员工原工号=RMS.RMS_ID OR DoradoReport.SAP工号=RMS.RMS_ID
LEFT outer join(select * from Domain_User where User_kind='Domain Users') Domain_User ON DoradoReport.员工原工号=Domain_User.user_id ;
------解决方案--------------------
这个问题很高深的,我反正看不懂,来打一下酱油