1: DECLARE @a table(id int, data int)
2: DECLARE @b table(id int, data int)
3: DECLARE @c table(id int, data int)
4:
5: insert into @a values(1, 9), (2, 8),(3,7)
6: insert into @b values(2, 6), (3, 5)
7: insert into @c values(1, 4), (2, 5)
8:
9: ;WITH CTE_IDs as
10: (
11: SELECT ID from @a
12: UNION
13: SELECT ID FROM @b
14: UNION
15: SELECT ID FROM @c
16: )
17: SELECT c.ID,t.* FROM CTE_IDs as c
18: cross apply
19: (
20: VALUES((select data from @a where id = c.id),
21: (select data from @b where id = c.id),
22: (select data from @c where id = c.id))
23: ) as t(a_data,b_data,c_data)
Thursday, 15 July 2021
Alternate way for FULL OUTER JOIN
Below is an one more way of doing FULL OUTER JOINs involving multiple tables. This gives a simpler approach, instead of having multiple OR conditions in subsequent tables.
Subscribe to:
Posts (Atom)
How to Handle SSIS Database movement from one environment to another
Below are the steps to follow the movement of SSISDB from one environment to another: -- opening the existing Database master key in S...
-
We are using Azure Data Factory to load data from Azure storage blobs to SQL Server on-premises. During data loading, we faced SQL Error: ...
-
Hello World, Through this blog, I am going to ruminate over lots of technical stuff around databases. Hoping to provide quality conten...
-
Below are the steps to follow the movement of SSISDB from one environment to another: -- opening the existing Database master key in S...