我正在通过 ODBC 连接到 NetSuite 数据库,并为数据库创建了一个相当大的查询来运行报告。我已将代码放在这篇文章的末尾。我的问题是,查询排除了“A_T_PROJECTS”表中“TRADING_PARTNER_ID”字段中具有 NULL 的行。我知道我可以在这里使用 RIGHT OUTER JOIN,但由于我要加入其他几个表,我似乎无法让它工作。关于我可以尝试什么的任何建议?
该连接是只读的,因此没有临时表 - 我希望它可以在单个查询中工作。谢谢你的时间!
SELECT
[A_T_CUSTOMERS].[COMPANYNAME] AS [Company Name],
[A_T_MILESTONES].[PROJECT_MILESTONE_NAME] AS [Name],
[A_T_PROJECTS].[COMPANYNAME] AS [Project Name],
[A_T_STATUS].[LIST_ITEM_NAME] AS [Status],
[A_T_MILESTONES].[DUE_DATE] AS [Milestone Due],
[A_T_ACTIONREQ].[LIST_ITEM_NAME] AS [Action Required By],
[A_T_PARTNERS].[COMPANYNAME] AS [Trading Partner],
[A_T_EMPLOYEES].[FULL_NAME] AS [Assigned To],
[A_T_CUSTOMERS].[ESTIMATED_DELIVERY_DATE] AS [Est Del Date],
CASE
WHEN [A_T_MILESTONES].[PROJECT_MILESTONE_NAME] = 'Project Complete/Move to Production'
THEN [A_T_MILESTONES].[DUE_DATE]
ELSE NULL
END AS [Est Move to Prod]
FROM
[CUSTOMERS] AS [A_T_CUSTOMERS],
[CUSTOMERS] AS [A_T_PROJECTS],
[PROJECT_MILESTONE] AS [A_T_MILESTONES],
[PARTNERS] AS [A_T_PARTNERS],
[STATUS] AS [A_T_STATUS],
[ACTION_REQUIRED] AS [A_T_ACTIONREQ],
[EMPLOYEES] AS [A_T_EMPLOYEES]
--RIGHT OUTER JOIN [PARTNERS] ON ([A_T_PARTNERS].[PARTNER_ID] = [A_T_PROJECTS].[TRADING_PARTNER_ID])
WHERE
-- JOIN CLAUSES --
[A_T_PROJECTS].[CUSTOMER_ID] = [A_T_MILESTONES].[PROJECT_NAME_ID]
AND [A_T_CUSTOMERS].[CUSTOMER_ID] = [A_T_MILESTONES].[CUSTOMER_MILESTONE_NAME_ID]
AND [A_T_PARTNERS].[PARTNER_ID] = [A_T_PROJECTS].[TRADING_PARTNER_ID]
AND [A_T_EMPLOYEES].[EMPLOYEE_ID] = [A_T_MILESTONES].[ASSIGNED_TO_ID]
AND [A_T_STATUS].[LIST_ID] = [A_T_MILESTONES].[STATUS_ID]
AND [A_T_ACTIONREQ].[LIST_ID] = [A_T_MILESTONES].[ACTION_REQUIRED_BY_ID]
-- FILTER CLAUSES --
AND [A_T_CUSTOMERS].[CUSTOMER_SINCE] > '2011-12-10 00:00:00'
AND ([A_T_MILESTONES].[STATUS_ID] = 1
OR [A_T_MILESTONES].[STATUS_ID] = 2
OR [A_T_MILESTONES].[STATUS_ID] = 3
OR [A_T_MILESTONES].[STATUS_ID] = 5)
AND ([A_T_PROJECTS].[STATUS] = 'Assigned'
OR [A_T_PROJECTS].[STATUS] = 'Delayed - per Customer'
OR [A_T_PROJECTS].[STATUS] = 'Delayed - per Internal'
OR [A_T_PROJECTS].[STATUS] = 'Delayed - per TP/VAN'
OR [A_T_PROJECTS].[STATUS] = 'In Progress'
OR [A_T_PROJECTS].[STATUS] = 'Production'
OR [A_T_PROJECTS].[STATUS] = 'On-Hold')
AND [A_T_CUSTOMERS].[TRANSLATOR_ID] != 4
AND [A_T_CUSTOMERS].[IN_PRODUCTION] = 'F'
AND ([A_T_PROJECTS].[JOB_TYPE_ID] IS NOT NULL
OR [A_T_PROJECTS].[JOB_TYPE_ID] != 8
OR [A_T_PROJECTS].[JOB_TYPE_ID] != 11)