0

I have a table that contains all the "Edges" between "Nodes" with relation "from node to node".

Table Nodes looks like this:

CREATE TABLE Nodes(
  Id VARCHAR(10) PRIMARY KEY,
  Name VARCHAR(50)
)

CREATE TABLE Edges(
  Id VARCHAR(100) PRIMARY KEY,
  FromId VARCHAR(10),
  ToId VARCHAR(10)
)

These tables are used to describe a network chart like the one rapresented in the image.

enter image description here

I have to create a recursive query in order to get all nodes the paths that pass throug "FROM" nodes and and arrive to "TO" nodes. I have also to avoid infinite loop like the one highlighted in yellow rectangle.

So basically the spider have to check for all the nodes the available paths, track the nodes that it has already passed and then go ahead till It reach "TO" nodes.

Then in a second moment, once I have all the routes, I need to test what are the routes thas has arrived to destination passing throug the FROM path.

How can i do this by Query ?

Thanks to support

DarioN1
  • 2,460
  • 7
  • 32
  • 67
  • Your question is not clear. Some sample data and expected results *as text tables* might help. – Gordon Linoff Mar 18 '21 at 12:18
  • [This](https://stackoverflow.com/a/42139978/92546) answer demonstrates one method for terminating recursion due to loops in the data. The path is available at the end of the exploration of the graph so you can search it as needed. – HABO Mar 18 '21 at 14:13
  • Better yet, have a look at [SQL Graph Architecture](https://learn.microsoft.com/en-us/sql/relational-databases/graphs/sql-graph-architecture?view=sql-server-ver15), available in modern versions (2017 and later) of SQL Server. – HABO Mar 18 '21 at 14:58
  • actually I can't use SQL Graph – DarioN1 Mar 18 '21 at 15:47

0 Answers0