Возможно ли выполнить подпрограмму JOIN для выражения Common Table? Если нет, то может ли кто-нибудь дать мне знать, как выполнять то, что я пытаюсь сделать ниже? Примеры были бы превосходными.
Например:
LEFT JOIN (
;WITH [UserDefined]
AS (SELECT *, -- Make sure we get only the latest revision.
ROW_NUMBER() OVER (PARTITION BY [ID]
ORDER BY [RevisionNumber] DESC) AS RN
FROM [syn_Change])
SELECT [UserDefined].[ID]
,[UserDefined].[ChangeNumber]
,[UserDefined].[Usr_CoResponsibility]
,[UserDefined].[Usr_StarFlowStatus]
FROM [UserDefined]
WHERE (RN = 1)
) [UserColumns]
ON [UserColumns].[ChangeNumber] = [CTE].[ChangeNumber]
Вот мой полный запрос:
;WITH CTE
AS (SELECT *, -- Make sure we get only the latest revision.
ROW_NUMBER() OVER (PARTITION BY [ItemID]
ORDER BY [RevisionNumber] DESC) AS RN
FROM [dw_Change])
SELECT [CTE].[ItemID]
,[CTE].[ViewID]
,[CTE].[FolderItemID]
,[CTE].[RevisionNumber]
,[CTE].[ChangeNumber]
,[CTE].[Synopsis]
,[CTE].[Description]
,[CTE].[EnteredOn]
,[CTE].[Responsibility]
--,[UserColumns].[Usr_CoResponsibility]
--,[UserColumns].[Usr_StarFlowStatus]
,[CTE].[Status] -- This will display the human name on the front-end with code.
,[Users].[F7] AS [ResponsibilityName]
,[GroupName].[Name] AS [AppGroupName]
,[AppName].[Name] AS [AppName]
FROM CTE
LEFT JOIN [S3] [Users] ON [Users].[F0] = [CTE].[Responsibility]
LEFT JOIN (SELECT [Name], [ViewID]
FROM [dw_Folder]
WHERE ([FolderItemID] = -1)) [GroupName]
ON [GroupName].[ViewID] = [CTE].[ViewID]
LEFT JOIN (SELECT [Name], [ItemID]
FROM [dw_Folder]
WHERE ([FolderItemID] <> -1)) [AppName]
ON [AppName].[ItemID] = [CTE].[FolderItemID]
LEFT JOIN (
;WITH [UserDefined]
AS (SELECT *, -- Make sure we get only the latest revision.
ROW_NUMBER() OVER (PARTITION BY [ID]
ORDER BY [RevisionNumber] DESC) AS RN
FROM [syn_Change])
SELECT [UserDefined].[ID]
,[UserDefined].[ChangeNumber]
,[UserDefined].[Usr_CoResponsibility]
,[UserDefined].[Usr_StarFlowStatus]
FROM [UserDefined]
WHERE (RN = 1)
) [UserColumns]
ON [UserColumns].[ChangeNumber] = [CTE].[ChangeNumber]
WHERE (RN = 1)
Большое спасибо!