Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Recursivel​y Fetch the Records in SQL Server using Functions

$
0
0

Hi Team,

I have the source table with two columns as in Point 1 and if the user writes the query for ex -330335 Risk ID, we need to get all the related Risk Id's as in the Target Table.

The query should be Dynamic based on the query written for that particular RISK ID

1) Source Table

Risk ID Related Risk
330335  328664 
330335  333025 
328664  327986 
328664  330335 
327986  328664  

2) Target Table (It is like a Recursively we need to cover all the Risk ID's Related to 330335 and once we cover all the RISK ID's we should Stop executing the Query)

Risk ID   Related Risk
330335  328664
330335  333025
330335  327986
330335  330335

My Requirement is how to create a target table as in Point 2.

Thanks!

Kiran


Viewing all articles
Browse latest Browse all 23857

Trending Articles