diff --git a/PostgreSQL.13/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.13).sql b/PostgreSQL.13/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.13).sql new file mode 100644 index 000000000000..d9c286aaf3f6 --- /dev/null +++ b/PostgreSQL.13/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.13).sql @@ -0,0 +1,76 @@ +BeforeExecute +-- PostgreSQL.13 PostgreSQL.9.5 PostgreSQL + +SELECT + t3."ColorName", + t3."StyleName", + t3."Conditional", + t3."StrValue" +FROM + ( + SELECT + CASE + WHEN CONCAT_WS(',', '', it."StyleName") IS NULL THEN NULL + ELSE CONCAT_WS(',', '', it."StyleName") || ':' || CASE + WHEN it."ColorId" IS NULL OR Length(it."ColorId"::text) >= 4 + THEN it."ColorId"::text + ELSE LPAD(it."ColorId"::text, 4, '0') + END + END as "StrValue", + it."ColorName", + it."StyleName", + it."Conditional" + FROM + "SomeItem" t2 + LEFT JOIN "SomeColor" "a_Color" ON t2."ColorId" = "a_Color"."Id" + LEFT JOIN "SomeStyle" "a_Style" ON t2."StyleId" = "a_Style"."Id" + LEFT JOIN LATERAL (VALUES + ("a_Color"."Name","a_Style"."Name",Coalesce(CASE + WHEN "a_Color"."Id" IS NULL THEN NULL + ELSE t2."ColorId" + END, 0),CASE + WHEN "a_Color"."Name" = 'Red' THEN ( + SELECT + COUNT(*) as "COUNT_1" + FROM + "SomeItem" t1 + ) + ELSE 0 + END), + (NULL,"a_Style"."Name",Coalesce(CASE + WHEN "a_Color"."Id" IS NULL THEN NULL + ELSE t2."ColorId" + END, 0),0) + ) it("ColorName", "StyleName", "ColorId", "Conditional") ON 1=1 + WHERE + it."ColorName" = 'Red' + ) t3 +ORDER BY + t3."StrValue" + +BeforeExecute +-- PostgreSQL.13 PostgreSQL.9.5 PostgreSQL + +SELECT + t1."Id", + t1."ColorId", + t1."StyleId", + "a_Color"."Id", + "a_Color"."Name", + "a_Style"."Id", + "a_Style"."Name" +FROM + "SomeItem" t1 + LEFT JOIN "SomeColor" "a_Color" ON t1."ColorId" = "a_Color"."Id" + LEFT JOIN "SomeStyle" "a_Style" ON t1."StyleId" = "a_Style"."Id" + +BeforeExecute +-- PostgreSQL.13 PostgreSQL.9.5 PostgreSQL + +SELECT + t1."Id", + t1."ColorId", + t1."StyleId" +FROM + "SomeItem" t1 + diff --git a/PostgreSQL.14/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.14).sql b/PostgreSQL.14/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.14).sql new file mode 100644 index 000000000000..4c0635549708 --- /dev/null +++ b/PostgreSQL.14/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.14).sql @@ -0,0 +1,76 @@ +BeforeExecute +-- PostgreSQL.14 PostgreSQL.9.5 PostgreSQL + +SELECT + t3."ColorName", + t3."StyleName", + t3."Conditional", + t3."StrValue" +FROM + ( + SELECT + CASE + WHEN CONCAT_WS(',', '', it."StyleName") IS NULL THEN NULL + ELSE CONCAT_WS(',', '', it."StyleName") || ':' || CASE + WHEN it."ColorId" IS NULL OR Length(it."ColorId"::text) >= 4 + THEN it."ColorId"::text + ELSE LPAD(it."ColorId"::text, 4, '0') + END + END as "StrValue", + it."ColorName", + it."StyleName", + it."Conditional" + FROM + "SomeItem" t2 + LEFT JOIN "SomeColor" "a_Color" ON t2."ColorId" = "a_Color"."Id" + LEFT JOIN "SomeStyle" "a_Style" ON t2."StyleId" = "a_Style"."Id" + LEFT JOIN LATERAL (VALUES + ("a_Color"."Name","a_Style"."Name",Coalesce(CASE + WHEN "a_Color"."Id" IS NULL THEN NULL + ELSE t2."ColorId" + END, 0),CASE + WHEN "a_Color"."Name" = 'Red' THEN ( + SELECT + COUNT(*) as "COUNT_1" + FROM + "SomeItem" t1 + ) + ELSE 0 + END), + (NULL,"a_Style"."Name",Coalesce(CASE + WHEN "a_Color"."Id" IS NULL THEN NULL + ELSE t2."ColorId" + END, 0),0) + ) it("ColorName", "StyleName", "ColorId", "Conditional") ON 1=1 + WHERE + it."ColorName" = 'Red' + ) t3 +ORDER BY + t3."StrValue" + +BeforeExecute +-- PostgreSQL.14 PostgreSQL.9.5 PostgreSQL + +SELECT + t1."Id", + t1."ColorId", + t1."StyleId", + "a_Color"."Id", + "a_Color"."Name", + "a_Style"."Id", + "a_Style"."Name" +FROM + "SomeItem" t1 + LEFT JOIN "SomeColor" "a_Color" ON t1."ColorId" = "a_Color"."Id" + LEFT JOIN "SomeStyle" "a_Style" ON t1."StyleId" = "a_Style"."Id" + +BeforeExecute +-- PostgreSQL.14 PostgreSQL.9.5 PostgreSQL + +SELECT + t1."Id", + t1."ColorId", + t1."StyleId" +FROM + "SomeItem" t1 + diff --git a/PostgreSQL.15/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.15).sql b/PostgreSQL.15/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.15).sql new file mode 100644 index 000000000000..858cf7fd60d2 --- /dev/null +++ b/PostgreSQL.15/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.15).sql @@ -0,0 +1,76 @@ +BeforeExecute +-- PostgreSQL.15 PostgreSQL + +SELECT + t3."ColorName", + t3."StyleName", + t3."Conditional", + t3."StrValue" +FROM + ( + SELECT + CASE + WHEN CONCAT_WS(',', '', it."StyleName") IS NULL THEN NULL + ELSE CONCAT_WS(',', '', it."StyleName") || ':' || CASE + WHEN it."ColorId" IS NULL OR Length(it."ColorId"::text) >= 4 + THEN it."ColorId"::text + ELSE LPAD(it."ColorId"::text, 4, '0') + END + END as "StrValue", + it."ColorName", + it."StyleName", + it."Conditional" + FROM + "SomeItem" t2 + LEFT JOIN "SomeColor" "a_Color" ON t2."ColorId" = "a_Color"."Id" + LEFT JOIN "SomeStyle" "a_Style" ON t2."StyleId" = "a_Style"."Id" + LEFT JOIN LATERAL (VALUES + ("a_Color"."Name","a_Style"."Name",Coalesce(CASE + WHEN "a_Color"."Id" IS NULL THEN NULL + ELSE t2."ColorId" + END, 0),CASE + WHEN "a_Color"."Name" = 'Red' THEN ( + SELECT + COUNT(*) as "COUNT_1" + FROM + "SomeItem" t1 + ) + ELSE 0 + END), + (NULL,"a_Style"."Name",Coalesce(CASE + WHEN "a_Color"."Id" IS NULL THEN NULL + ELSE t2."ColorId" + END, 0),0) + ) it("ColorName", "StyleName", "ColorId", "Conditional") ON 1=1 + WHERE + it."ColorName" = 'Red' + ) t3 +ORDER BY + t3."StrValue" + +BeforeExecute +-- PostgreSQL.15 PostgreSQL + +SELECT + t1."Id", + t1."ColorId", + t1."StyleId", + "a_Color"."Id", + "a_Color"."Name", + "a_Style"."Id", + "a_Style"."Name" +FROM + "SomeItem" t1 + LEFT JOIN "SomeColor" "a_Color" ON t1."ColorId" = "a_Color"."Id" + LEFT JOIN "SomeStyle" "a_Style" ON t1."StyleId" = "a_Style"."Id" + +BeforeExecute +-- PostgreSQL.15 PostgreSQL + +SELECT + t1."Id", + t1."ColorId", + t1."StyleId" +FROM + "SomeItem" t1 + diff --git a/PostgreSQL.16/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.16).sql b/PostgreSQL.16/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.16).sql new file mode 100644 index 000000000000..96733d8b03ae --- /dev/null +++ b/PostgreSQL.16/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.16).sql @@ -0,0 +1,76 @@ +BeforeExecute +-- PostgreSQL.16 PostgreSQL.15 PostgreSQL + +SELECT + t3."ColorName", + t3."StyleName", + t3."Conditional", + t3."StrValue" +FROM + ( + SELECT + CASE + WHEN CONCAT_WS(',', '', it."StyleName") IS NULL THEN NULL + ELSE CONCAT_WS(',', '', it."StyleName") || ':' || CASE + WHEN it."ColorId" IS NULL OR Length(it."ColorId"::text) >= 4 + THEN it."ColorId"::text + ELSE LPAD(it."ColorId"::text, 4, '0') + END + END as "StrValue", + it."ColorName", + it."StyleName", + it."Conditional" + FROM + "SomeItem" t2 + LEFT JOIN "SomeColor" "a_Color" ON t2."ColorId" = "a_Color"."Id" + LEFT JOIN "SomeStyle" "a_Style" ON t2."StyleId" = "a_Style"."Id" + LEFT JOIN LATERAL (VALUES + ("a_Color"."Name","a_Style"."Name",Coalesce(CASE + WHEN "a_Color"."Id" IS NULL THEN NULL + ELSE t2."ColorId" + END, 0),CASE + WHEN "a_Color"."Name" = 'Red' THEN ( + SELECT + COUNT(*) as "COUNT_1" + FROM + "SomeItem" t1 + ) + ELSE 0 + END), + (NULL,"a_Style"."Name",Coalesce(CASE + WHEN "a_Color"."Id" IS NULL THEN NULL + ELSE t2."ColorId" + END, 0),0) + ) it("ColorName", "StyleName", "ColorId", "Conditional") ON 1=1 + WHERE + it."ColorName" = 'Red' + ) t3 +ORDER BY + t3."StrValue" + +BeforeExecute +-- PostgreSQL.16 PostgreSQL.15 PostgreSQL + +SELECT + t1."Id", + t1."ColorId", + t1."StyleId", + "a_Color"."Id", + "a_Color"."Name", + "a_Style"."Id", + "a_Style"."Name" +FROM + "SomeItem" t1 + LEFT JOIN "SomeColor" "a_Color" ON t1."ColorId" = "a_Color"."Id" + LEFT JOIN "SomeStyle" "a_Style" ON t1."StyleId" = "a_Style"."Id" + +BeforeExecute +-- PostgreSQL.16 PostgreSQL.15 PostgreSQL + +SELECT + t1."Id", + t1."ColorId", + t1."StyleId" +FROM + "SomeItem" t1 + diff --git a/PostgreSQL.17/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.17).sql b/PostgreSQL.17/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.17).sql new file mode 100644 index 000000000000..b203c4ac1214 --- /dev/null +++ b/PostgreSQL.17/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.17).sql @@ -0,0 +1,76 @@ +BeforeExecute +-- PostgreSQL.17 PostgreSQL.15 PostgreSQL + +SELECT + t3."ColorName", + t3."StyleName", + t3."Conditional", + t3."StrValue" +FROM + ( + SELECT + CASE + WHEN CONCAT_WS(',', '', it."StyleName") IS NULL THEN NULL + ELSE CONCAT_WS(',', '', it."StyleName") || ':' || CASE + WHEN it."ColorId" IS NULL OR Length(it."ColorId"::text) >= 4 + THEN it."ColorId"::text + ELSE LPAD(it."ColorId"::text, 4, '0') + END + END as "StrValue", + it."ColorName", + it."StyleName", + it."Conditional" + FROM + "SomeItem" t2 + LEFT JOIN "SomeColor" "a_Color" ON t2."ColorId" = "a_Color"."Id" + LEFT JOIN "SomeStyle" "a_Style" ON t2."StyleId" = "a_Style"."Id" + LEFT JOIN LATERAL (VALUES + ("a_Color"."Name","a_Style"."Name",Coalesce(CASE + WHEN "a_Color"."Id" IS NULL THEN NULL + ELSE t2."ColorId" + END, 0),CASE + WHEN "a_Color"."Name" = 'Red' THEN ( + SELECT + COUNT(*) as "COUNT_1" + FROM + "SomeItem" t1 + ) + ELSE 0 + END), + (NULL,"a_Style"."Name",Coalesce(CASE + WHEN "a_Color"."Id" IS NULL THEN NULL + ELSE t2."ColorId" + END, 0),0) + ) it("ColorName", "StyleName", "ColorId", "Conditional") ON 1=1 + WHERE + it."ColorName" = 'Red' + ) t3 +ORDER BY + t3."StrValue" + +BeforeExecute +-- PostgreSQL.17 PostgreSQL.15 PostgreSQL + +SELECT + t1."Id", + t1."ColorId", + t1."StyleId", + "a_Color"."Id", + "a_Color"."Name", + "a_Style"."Id", + "a_Style"."Name" +FROM + "SomeItem" t1 + LEFT JOIN "SomeColor" "a_Color" ON t1."ColorId" = "a_Color"."Id" + LEFT JOIN "SomeStyle" "a_Style" ON t1."StyleId" = "a_Style"."Id" + +BeforeExecute +-- PostgreSQL.17 PostgreSQL.15 PostgreSQL + +SELECT + t1."Id", + t1."ColorId", + t1."StyleId" +FROM + "SomeItem" t1 + diff --git a/PostgreSQL.18/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.18).sql b/PostgreSQL.18/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.18).sql new file mode 100644 index 000000000000..c7f7ac13935a --- /dev/null +++ b/PostgreSQL.18/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(PostgreSQL.18).sql @@ -0,0 +1,76 @@ +BeforeExecute +-- PostgreSQL.18 PostgreSQL + +SELECT + t3."ColorName", + t3."StyleName", + t3."Conditional", + t3."StrValue" +FROM + ( + SELECT + CASE + WHEN CONCAT_WS(',', '', it."StyleName") IS NULL THEN NULL + ELSE CONCAT_WS(',', '', it."StyleName") || ':' || CASE + WHEN it."ColorId" IS NULL OR Length(it."ColorId"::text) >= 4 + THEN it."ColorId"::text + ELSE LPAD(it."ColorId"::text, 4, '0') + END + END as "StrValue", + it."ColorName", + it."StyleName", + it."Conditional" + FROM + "SomeItem" t2 + LEFT JOIN "SomeColor" "a_Color" ON t2."ColorId" = "a_Color"."Id" + LEFT JOIN "SomeStyle" "a_Style" ON t2."StyleId" = "a_Style"."Id" + LEFT JOIN LATERAL (VALUES + ("a_Color"."Name","a_Style"."Name",Coalesce(CASE + WHEN "a_Color"."Id" IS NULL THEN NULL + ELSE t2."ColorId" + END, 0),CASE + WHEN "a_Color"."Name" = 'Red' THEN ( + SELECT + COUNT(*) as "COUNT_1" + FROM + "SomeItem" t1 + ) + ELSE 0 + END), + (NULL,"a_Style"."Name",Coalesce(CASE + WHEN "a_Color"."Id" IS NULL THEN NULL + ELSE t2."ColorId" + END, 0),0) + ) it("ColorName", "StyleName", "ColorId", "Conditional") ON 1=1 + WHERE + it."ColorName" = 'Red' + ) t3 +ORDER BY + t3."StrValue" + +BeforeExecute +-- PostgreSQL.18 PostgreSQL + +SELECT + t1."Id", + t1."ColorId", + t1."StyleId", + "a_Color"."Id", + "a_Color"."Name", + "a_Style"."Id", + "a_Style"."Name" +FROM + "SomeItem" t1 + LEFT JOIN "SomeColor" "a_Color" ON t1."ColorId" = "a_Color"."Id" + LEFT JOIN "SomeStyle" "a_Style" ON t1."StyleId" = "a_Style"."Id" + +BeforeExecute +-- PostgreSQL.18 PostgreSQL + +SELECT + t1."Id", + t1."ColorId", + t1."StyleId" +FROM + "SomeItem" t1 + diff --git a/SqlServer.2005.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2005.MS).sql b/SqlServer.2005.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2005.MS).sql new file mode 100644 index 000000000000..a03e2d709411 --- /dev/null +++ b/SqlServer.2005.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2005.MS).sql @@ -0,0 +1,77 @@ +BeforeExecute +-- SqlServer.2005.MS SqlServer.2005 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + CASE + WHEN SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) IS NULL + THEN NULL + ELSE SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) + N':' + CASE + WHEN [it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5 + THEN CAST([it].[ColorId] AS NVarChar(11)) + ELSE REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)) + END + END as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY ( + SELECT [a_Color].[Name] AS [ColorName], [a_Style].[Name] AS [StyleName], Coalesce(CASE + WHEN [a_Color].[Id] IS NULL THEN NULL + ELSE [t2].[ColorId] + END, 0) AS [ColorId], CASE + WHEN [a_Color].[Name] = N'Red' THEN ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ) + ELSE 0 + END AS [Conditional] + UNION ALL + SELECT NULL, [a_Style].[Name], Coalesce(CASE + WHEN [a_Color].[Id] IS NULL THEN NULL + ELSE [t2].[ColorId] + END, 0), 0) [it] + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2005.MS SqlServer.2005 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2005.MS SqlServer.2005 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2005/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2005).sql b/SqlServer.2005/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2005).sql new file mode 100644 index 000000000000..7a38121bdd84 --- /dev/null +++ b/SqlServer.2005/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2005).sql @@ -0,0 +1,77 @@ +BeforeExecute +-- SqlServer.2005 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + CASE + WHEN SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) IS NULL + THEN NULL + ELSE SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) + N':' + CASE + WHEN [it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5 + THEN CAST([it].[ColorId] AS NVarChar(11)) + ELSE REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)) + END + END as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY ( + SELECT [a_Color].[Name] AS [ColorName], [a_Style].[Name] AS [StyleName], Coalesce(CASE + WHEN [a_Color].[Id] IS NULL THEN NULL + ELSE [t2].[ColorId] + END, 0) AS [ColorId], CASE + WHEN [a_Color].[Name] = N'Red' THEN ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ) + ELSE 0 + END AS [Conditional] + UNION ALL + SELECT NULL, [a_Style].[Name], Coalesce(CASE + WHEN [a_Color].[Id] IS NULL THEN NULL + ELSE [t2].[ColorId] + END, 0), 0) [it] + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2005 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2005 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2008.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2008.MS).sql b/SqlServer.2008.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2008.MS).sql new file mode 100644 index 000000000000..217a489afa89 --- /dev/null +++ b/SqlServer.2008.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2008.MS).sql @@ -0,0 +1,77 @@ +BeforeExecute +-- SqlServer.2008.MS SqlServer.2008 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + CASE + WHEN SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) IS NULL + THEN NULL + ELSE SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) + N':' + CASE + WHEN [it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5 + THEN CAST([it].[ColorId] AS NVarChar(11)) + ELSE REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)) + END + END as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(CASE + WHEN [a_Color].[Id] IS NULL THEN NULL + ELSE [t2].[ColorId] + END, 0),CASE + WHEN [a_Color].[Name] = N'Red' THEN ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ) + ELSE 0 + END), + (NULL,[a_Style].[Name],Coalesce(CASE + WHEN [a_Color].[Id] IS NULL THEN NULL + ELSE [t2].[ColorId] + END, 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2008.MS SqlServer.2008 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2008.MS SqlServer.2008 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2008/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2008).sql b/SqlServer.2008/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2008).sql new file mode 100644 index 000000000000..28f70831beb4 --- /dev/null +++ b/SqlServer.2008/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2008).sql @@ -0,0 +1,77 @@ +BeforeExecute +-- SqlServer.2008 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + CASE + WHEN SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) IS NULL + THEN NULL + ELSE SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) + N':' + CASE + WHEN [it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5 + THEN CAST([it].[ColorId] AS NVarChar(11)) + ELSE REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)) + END + END as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(CASE + WHEN [a_Color].[Id] IS NULL THEN NULL + ELSE [t2].[ColorId] + END, 0),CASE + WHEN [a_Color].[Name] = N'Red' THEN ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ) + ELSE 0 + END), + (NULL,[a_Style].[Name],Coalesce(CASE + WHEN [a_Color].[Id] IS NULL THEN NULL + ELSE [t2].[ColorId] + END, 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2008 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2008 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2012.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2012.MS).sql b/SqlServer.2012.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2012.MS).sql new file mode 100644 index 000000000000..07377b7751d1 --- /dev/null +++ b/SqlServer.2012.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2012.MS).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.2012.MS SqlServer.2012 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) IS NULL, NULL, SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2012.MS SqlServer.2012 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2012.MS SqlServer.2012 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2012/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2012).sql b/SqlServer.2012/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2012).sql new file mode 100644 index 000000000000..4fc3f01b676c --- /dev/null +++ b/SqlServer.2012/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2012).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.2012 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) IS NULL, NULL, SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2012 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2012 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2014.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2014.MS).sql b/SqlServer.2014.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2014.MS).sql new file mode 100644 index 000000000000..4f8080dccde9 --- /dev/null +++ b/SqlServer.2014.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2014.MS).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.2014.MS SqlServer.2014 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) IS NULL, NULL, SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2014.MS SqlServer.2014 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2014.MS SqlServer.2014 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2014/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2014).sql b/SqlServer.2014/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2014).sql new file mode 100644 index 000000000000..f83cbb1ec7e0 --- /dev/null +++ b/SqlServer.2014/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2014).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.2014 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) IS NULL, NULL, SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2014 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2014 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2016.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2016.MS).sql b/SqlServer.2016.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2016.MS).sql new file mode 100644 index 000000000000..6132ad8cbb57 --- /dev/null +++ b/SqlServer.2016.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2016.MS).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.2016.MS SqlServer.2016 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) IS NULL, NULL, SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2016.MS SqlServer.2016 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2016.MS SqlServer.2016 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2016/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2016).sql b/SqlServer.2016/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2016).sql new file mode 100644 index 000000000000..8fa28e447ae5 --- /dev/null +++ b/SqlServer.2016/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2016).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.2016 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) IS NULL, NULL, SUBSTRING((ISNULL((N',' + N''), '') + ISNULL((N',' + [it].[StyleName]), '')), LEN(CONVERT(NVARCHAR(MAX), N',') + N'!'), 8000) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2016 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2016 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2017.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2017.MS).sql b/SqlServer.2017.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2017.MS).sql new file mode 100644 index 000000000000..3499aa548088 --- /dev/null +++ b/SqlServer.2017.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2017.MS).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.2017.MS SqlServer.2017 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(CONCAT_WS(N',', N'', [it].[StyleName]) IS NULL, NULL, CONCAT_WS(N',', N'', [it].[StyleName]) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2017.MS SqlServer.2017 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2017.MS SqlServer.2017 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2017/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2017).sql b/SqlServer.2017/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2017).sql new file mode 100644 index 000000000000..a18e01bb147d --- /dev/null +++ b/SqlServer.2017/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2017).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.2017 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(CONCAT_WS(N',', N'', [it].[StyleName]) IS NULL, NULL, CONCAT_WS(N',', N'', [it].[StyleName]) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2017 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2017 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2019.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2019.MS).sql b/SqlServer.2019.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2019.MS).sql new file mode 100644 index 000000000000..b14dcc814bbb --- /dev/null +++ b/SqlServer.2019.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2019.MS).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.2019.MS SqlServer.2019 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(CONCAT_WS(N',', N'', [it].[StyleName]) IS NULL, NULL, CONCAT_WS(N',', N'', [it].[StyleName]) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2019.MS SqlServer.2019 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2019.MS SqlServer.2019 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2019/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2019).sql b/SqlServer.2019/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2019).sql new file mode 100644 index 000000000000..cd831de6124d --- /dev/null +++ b/SqlServer.2019/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2019).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.2019 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(CONCAT_WS(N',', N'', [it].[StyleName]) IS NULL, NULL, CONCAT_WS(N',', N'', [it].[StyleName]) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2019 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2019 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2022.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2022.MS).sql b/SqlServer.2022.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2022.MS).sql new file mode 100644 index 000000000000..8b2aa907e5eb --- /dev/null +++ b/SqlServer.2022.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2022.MS).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.2022.MS SqlServer.2022 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(CONCAT_WS(N',', N'', [it].[StyleName]) IS NULL, NULL, CONCAT_WS(N',', N'', [it].[StyleName]) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2022.MS SqlServer.2022 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2022.MS SqlServer.2022 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2022/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2022).sql b/SqlServer.2022/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2022).sql new file mode 100644 index 000000000000..6a1c1121c430 --- /dev/null +++ b/SqlServer.2022/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2022).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.2022 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(CONCAT_WS(N',', N'', [it].[StyleName]) IS NULL, NULL, CONCAT_WS(N',', N'', [it].[StyleName]) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2022 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2022 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2025.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2025.MS).sql b/SqlServer.2025.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2025.MS).sql new file mode 100644 index 000000000000..6ec22505a2c8 --- /dev/null +++ b/SqlServer.2025.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2025.MS).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.2025.MS SqlServer.2025 SqlServer.2022 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(CONCAT_WS(N',', N'', [it].[StyleName]) IS NULL, NULL, CONCAT_WS(N',', N'', [it].[StyleName]) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2025.MS SqlServer.2025 SqlServer.2022 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2025.MS SqlServer.2025 SqlServer.2022 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.2025/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2025).sql b/SqlServer.2025/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2025).sql new file mode 100644 index 000000000000..2c6930a98e62 --- /dev/null +++ b/SqlServer.2025/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.2025).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.2025 SqlServer.2022 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(CONCAT_WS(N',', N'', [it].[StyleName]) IS NULL, NULL, CONCAT_WS(N',', N'', [it].[StyleName]) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.2025 SqlServer.2022 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.2025 SqlServer.2022 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.Contained.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.Contained.MS).sql b/SqlServer.Contained.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.Contained.MS).sql new file mode 100644 index 000000000000..68bd9332294f --- /dev/null +++ b/SqlServer.Contained.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.Contained.MS).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.Contained.MS SqlServer.2019 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(CONCAT_WS(N',', N'', [it].[StyleName]) IS NULL, NULL, CONCAT_WS(N',', N'', [it].[StyleName]) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.Contained.MS SqlServer.2019 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.Contained.MS SqlServer.2019 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.Contained/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.Contained).sql b/SqlServer.Contained/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.Contained).sql new file mode 100644 index 000000000000..3c44cf8c8a7f --- /dev/null +++ b/SqlServer.Contained/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.Contained).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.Contained SqlServer.2019 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(CONCAT_WS(N',', N'', [it].[StyleName]) IS NULL, NULL, CONCAT_WS(N',', N'', [it].[StyleName]) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.Contained SqlServer.2019 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.Contained SqlServer.2019 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.SA.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.SA.MS).sql b/SqlServer.SA.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.SA.MS).sql new file mode 100644 index 000000000000..8b4935e0d5d3 --- /dev/null +++ b/SqlServer.SA.MS/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.SA.MS).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.SA.MS SqlServer.2019 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(CONCAT_WS(N',', N'', [it].[StyleName]) IS NULL, NULL, CONCAT_WS(N',', N'', [it].[StyleName]) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.SA.MS SqlServer.2019 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.SA.MS SqlServer.2019 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] + diff --git a/SqlServer.SA/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.SA).sql b/SqlServer.SA/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.SA).sql new file mode 100644 index 000000000000..205a8796a828 --- /dev/null +++ b/SqlServer.SA/Tests/Linq/EnumerableInQuery/Tests.Linq.EnumerableInQuery.CoalesceColumnSelection(SqlServer.SA).sql @@ -0,0 +1,60 @@ +BeforeExecute +-- SqlServer.SA SqlServer.2019 + +SELECT + [t3].[ColorName], + [t3].[StyleName], + [t3].[Conditional], + [t3].[StrValue] +FROM + ( + SELECT + IIF(CONCAT_WS(N',', N'', [it].[StyleName]) IS NULL, NULL, CONCAT_WS(N',', N'', [it].[StyleName]) + N':' + IIF([it].[ColorId] IS NULL OR LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') >= 5, CAST([it].[ColorId] AS NVarChar(11)), REPLICATE(N'0', 4 - (LEN(CAST([it].[ColorId] AS NVarChar(11)) + N'.') - 1)) + CAST([it].[ColorId] AS NVarChar(11)))) as [StrValue], + [it].[ColorName], + [it].[StyleName], + [it].[Conditional] + FROM + [SomeItem] [t2] + LEFT JOIN [SomeColor] [a_Color] ON [t2].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t2].[StyleId] = [a_Style].[Id] + OUTER APPLY (VALUES + ([a_Color].[Name],[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),IIF([a_Color].[Name] = N'Red', ( + SELECT + COUNT(*) as [COUNT_1] + FROM + [SomeItem] [t1] + ), 0)), + (NULL,[a_Style].[Name],Coalesce(IIF([a_Color].[Id] IS NULL, NULL, [t2].[ColorId]), 0),0) + ) [it]([ColorName], [StyleName], [ColorId], [Conditional]) + WHERE + [it].[ColorName] = N'Red' + ) [t3] +ORDER BY + [t3].[StrValue] + +BeforeExecute +-- SqlServer.SA SqlServer.2019 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId], + [a_Color].[Id], + [a_Color].[Name], + [a_Style].[Id], + [a_Style].[Name] +FROM + [SomeItem] [t1] + LEFT JOIN [SomeColor] [a_Color] ON [t1].[ColorId] = [a_Color].[Id] + LEFT JOIN [SomeStyle] [a_Style] ON [t1].[StyleId] = [a_Style].[Id] + +BeforeExecute +-- SqlServer.SA SqlServer.2019 + +SELECT + [t1].[Id], + [t1].[ColorId], + [t1].[StyleId] +FROM + [SomeItem] [t1] +