다음과 같은 SQL을 작성 했습니다.
보시는 바와 같이 select한 결과 값을 가지고 다시 전체를 select 하고 있습니다.
②의 결과 값으로만 다 표현을 하고 싶은데 제 실력으론 참 힘드네요.
★★★①의 문장을 없애고 ★★★②의 문장으로 겨과 값을 표현 하고자 합니다.
고수님들의 조언 부탁 드립니다.
----------------------------------------------------------------------------------------------------------------------
(@p__linq__0 varchar(8000))SELECT --★★★①
[Project2].[C1] AS [C1], [Project2].[JHJUNO] AS [JHJUNO], [Project2].[C2] AS [C2], [Project2].[TJH1000J_id] AS [TJH1000J_id],
[Project2].[DateCreated] AS [DateCreated], [Project2].[ModifiedDate] AS [ModifiedDate], [Project2].[UpdatedBy] AS [UpdatedBy], [Project2].[ISREMOVED] AS [ISREMOVED],
[Project2].[WorkInfo] AS [WorkInfo], [Project2].[JOKEY] AS [JOKEY], [Project2].[JOTYDT] AS [JOTYDT],
[Project2].[JHSEQC] AS [JHSEQC], [Project2].[JHVJUN] AS [JHVJUN]
FROM ( SELECT --★★★②
[Distinct1].[JHJUNO] AS [JHJUNO],
1 AS [C1],
[Extent2].[TJH1000J_id] AS [TJH1000J_id], [Extent2].[DateCreated] AS [DateCreated], [Extent2].[ModifiedDate] AS [ModifiedDate], [Extent2].[UpdatedBy] AS [UpdatedBy],
[Extent2].[ISREMOVED] AS [ISREMOVED], [Extent2].[WorkInfo] AS [WorkInfo], [Extent2].[JOKEY] AS [JOKEY], [Extent2].[JOTYDT] AS [JOTYDT],
[Extent2].[JHSEQC] AS [JHSEQC], [Extent2].[JHVJUN] AS [JHVJUN],
CASE WHEN ([Extent2].[TJH1000J_id] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C2]
FROM (SELECT DISTINCT [Extent1].[JHJUNO] AS [JHJUNO]
FROM [com_tran].[as_TJH1000J] AS [Extent1]
WHERE ([Extent1].[JHVJUN] = @p__linq__0)
OR (([Extent1].[JHVJUN] IS NULL)
AND (@p__linq__0 IS NULL)) ) AS [Distinct1]
LEFT OUTER JOIN [com_tran].[as_TJH1000J] AS [Extent2] ON (([Extent2].[JHVJUN] = @p__linq__0) OR (([Extent2].[JHVJUN] IS NULL) AND (@p__linq__0 IS NULL)))
AND ([Distinct1].[JHJUNO] = [Extent2].[JHJUNO])
) AS [Project2]
ORDER BY [Project2].[JHJUNO] ASC, [Project2].[C2] ASC |