我正在使用 SQL Server Express,我正在尝试使用LEFT OUTER JOIN
. 它工作得很好,但前提是所有列都存在。因此,过去一个小时我一直在阅读如何添加条件,以便LEFT OUTER JOIN
仅在列存在时才这样做。
请参阅下面的代码(问题是最后一个LEFT OUTER JOIN
,因为a.[Page Path]
不存在):
SELECT
b.[Page ID],
ISNULL(b.[Page Group],'Other Landing Page') AS [Landing Page Group],
ISNULL(c.[Page Group],'Other Second Page') AS [Second Page Group],
ISNULL(d.[Page Group],'Other Page') AS [Page Path Group],
a.*
FROM [mychoice-data-b9BwZvd] a
LEFT OUTER JOIN [mychoice-pagedims] b
ON
(a.[Landing Page Path] LIKE b.[Page ID])
LEFT OUTER JOIN [mychoice-pagedims] c
ON
(a.[Second Page Path] LIKE c.[Page ID])
LEFT OUTER JOIN [mychoice-pagedims] d
ON
a.[Page Path] LIKE d.[Page ID]
WHERE a.[Page Path] IS NOT NULL
我试过IF(EXISTS
了,但无论我做什么,我都会收到一个错误“无效的列名'页面路径'”。