I have a function GetChildren(@id uniqueidentifier) that returns a table of nodes and a table of parents deleted from delete trigger
I want to make a big table of nodes concatenating output of GetChildren for each row.Id of deleted, how do I do that? Please, say how to make it without variables and loops in only pure sql-way
I want something similar to SelectMany from linq c#
example:
deleted table
+-----+
| Id |
+-----+
| 111 |
+-----+
| 222 |
+-----+
Nodes table
+-----+----------+
| Id | ParentId |
+-----+----------+
| 111 | ... |
+-----+----------+
| 222 | ... |
+-----+----------+
| 333 | ... |
+-----+----------+
| 444 | 111 |
+-----+----------+
| 555 | null |
+-----+----------+
| 666 | 222 |
+-----+----------+
GetChildren('111') will produce:
+-----+
| Id |
+-----+
| 111 |
+-----+
| 444 |
+-----+
GetChildren('222') will produce:
+-----+
| Id |
+-----+
| 222 |
+-----+
| 666 |
+-----+
I want to get table that is concatenation of 2 above:
+-----+
| Id |
+-----+
| 111 |
+-----+
| 444 |
+-----+
| 222 |
+-----+
| 666 |
+-----+
If deleted would contain 4 rows I want to concatenate all 4 outputs of GetChildren for each row