473,386 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

recursive logic with sql server

I was able to write a recursive logic in c# and because of performance issue I need to write this in Stored Proc or UDF in SQL Server. I have following tables and I would appreciate if any one can suggest me how to do something like this
Table EQ- ID, Name, SYSID (nullable)
Table RD - ID, Name
Table EQ_RD_Xref - EQ_RD_XrefID, EQID, RDID (EQ and RD have many to many relationship)
Table SMAST - MASTERID, MasterName
Table EQ_SMAST_XREF - EQ_SMAST_XREF,MASTERID,EQID
Table SYS - SYSID, SYSName

Whenever I want to get the dependencies for EQ BY ID it should give me entire forest of EQ's (tied to EQ_SMAST_XREF and these EQ's may have SYS or other RD's), RD's (these RD's may have some other EQ's) and Sys. The forest should have only the items in the forest and not any other item
Thanks for any help in advance
Jan 7 '10 #1
3 2149
Delerna
1,134 Expert 1GB
Recursive logic is handled in TSQL via the Cursor, so try searching SQL servers help documentation for "Cursor".

Bear in mind that, for performance reasons, the use of cursors is frowned upon.
There are situations where a cursor is the only means by which a task can be accomplished but these are rare. It is almost always possible to do something via vastly more efficient, "set" based queries where the recordset is processed as a whole instead of one record at a time.
Jan 11 '10 #2
nbiswas
149 100+
Also you can use Recursive CTE's if you are using Sql Server 2005+

Here is an example

SQL SERVER – Simple Example of Recursive CTE
Mar 24 '10 #3
nbiswas
149 100+
You may also find interest in Recursive Stored Procs.

Using recursion in stored procedures
Mar 24 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: fighterman19 | last post by:
because in linked list each node contains only one digit like curr->nodevalue_1= 0 curr->nodevalue_2=1 sum->nodevalue = curr->nodevalue_1 + curr->nodevalue_2 so when the number go up to >10...
4
by: Rodusa | last post by:
I am having problem to apply updates into this function below. I tried using cursor for updates, etc. but no success. Sql server keeps telling me that I cannot execute insert or update from inside...
4
by: deko | last post by:
When I loop through this function, it works fine until it hits End Function - then it jumps to End Select. Very strange... This behavior occurs when Case = 255. Any ideas why this is happening? ...
4
by: Elmo Watson | last post by:
Is there a way, with the System.IO class, to do a recursive list of a directory structure? For instance, in DirectoryInfo, you have GetDirectories and GetFiles .... In Directory, you have...
1
by: Dane Carty | last post by:
Hi, Using a TreeView component to create a tree of the directories within my file system. I can't get my head around the logic of the recursion. Anyone with a bigger brain is welcome to...
3
by: maev | last post by:
Warm welcome to all of you, programmers. In fact I'm beginning my journey with coding, and I just encountered my first real problem. I would like to find the solution by my own, but it isn't...
10
by: zahy[dot]bnaya[At]gmail[dot]com | last post by:
Hi, I am trying to come up with a c style string reverser, I want it to take 1 argument Altough I would never do this in real life. Is there a way to do it? I wrote this function that fails : ...
14
by: rabbitrun | last post by:
Hi Everyone, I work for a financial company. I am planning to give a presentation to rest of the development team (15 people) here on moving server side logic to client-side javascript for an...
0
by: champ1979 | last post by:
I wrote an algorithm to get all the relatives of a person in a family tree. I'm basically getting all the users from the DB and am doing the recursive logic in code, so that there is only 1 call...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.