473,791 Members | 3,179 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

T-SQL: Recursion and circular references

balabaster
797 Recognized Expert Contributor
Hi,

I have a couple of tables:

Expand|Select|Wrap|Line Numbers
  1. Units(
  2.   Unit_PKey Int Identity(1,1) Primary Key,
  3.   Unit_Name nvarchar(8),
  4.   Unit_Description nvarchar(32)
  5. )
1, lb, Pounds
2, cwt, Hundredweight
3, kg, Kilograms

Expand|Select|Wrap|Line Numbers
  1. Conversions(
  2.   Cnvrt_PKey Int Identity(1,1) Primary Key,
  3.   Cnvrt_FromUnit Int Foreign Key References Units.Unit_PKey,
  4.   Cnvrt_ToUnit Int Foreign Key References Units.Unit_PKey, 
  5.   Cnvrt_Formula
  6. )
I am trying to build a recursive stored procedure that will handle transitive relationships, but I'm having some issues accounting for potential circular references.

Say I have the following table data (I will display the unit names with their keys in brackets so it's easier to follow.)

1, lb (1), cwt (2), {FROM}/100
2, cwt (2), lb (1), {FROM}*100
3, lb (1), kg (3), {FROM}/2.2046
4, kg (3), lb (1), {FROM}*2.2046

Obviously there is no formula in this table accounting for the conversion from kg to cwt, but a transitive relationship exists, such that (kg*2.2046)/100 converts kg to lbs.

In an ideal world, a formula would be in the database that allows the conversion directly kg*0.022046, and for performance purposes, I would push the users of this data to have formulae for direct conversions, but in the event someone's asleep at the wheel and no direct formula exists, I would like the system to build this transitive relationship.

A recursive procedure is easy enough to build, but I'm wondering what would be the best way to handle potentially disasterous circular references... I thought of passing up a list of previously checked "FromUnit"s thus allowing a select where the Cnvrt_ToUnit is not found in that list, and thus avoiding that scenario... the question is, what is the best way to pass this list up through the call stack?

My first thought is a temporary table, but:
  • A global temp table (##MyTempTable for instance) is visible across the whole system... what happens if multiple people call this procedure at the same time?
  • A local temporary table #MyTempTable isn't visible to each level of the call stack
  • A table variable can neither be passed as an input or an output to a stored procedure...

So where do I go from here? Any thoughts would be most welcome.
Aug 21 '08 #1
0 2829

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

Similar topics

3
5654
by: Christine McGavran | last post by:
I have created an xml format for describing a custom user interface. My application successfully parses and displays the UI described in xml files created in that format. Before today we were using Visual Studio .net 2002. I created a schema file to describe my xml so that I could use the fancy xml editing capabilities in the Visual Studio enviroment. With this schema referenced, I could auto-complete while scripting xml for my user...
16
2845
by: Kiuhnm | last post by:
Is there an elegant way to deal with semi-circular definitions? Semi-circular definition: A { B }; B { *A }; Circular reference: A { *B }; B { *A }; The problems arise when there are more semi-circular definitions and
2
7984
by: Earth Worm Jim | last post by:
I have been able to get simple circular references to be serialized in xml by using the ImportTypeMapping method on the SoapReflectionImporter class. But I am unable to serialise circular references when the circular reference is contained with in a collection class, specifically I am using a custom ArrayList object. I keep getting a StackOverFlow Exception from the XmlSerializer class when attempting the serialisation. The classes...
8
3504
by: Eric Eggermann | last post by:
I'm having a problem with really large file sizes when serializing the classes that describe my little document. There are some circular references which result in the same object getting written to disk multiple times. Now I'm using just basic serialization as described in MSDN. Clearly, I need to stop serializing these parent references, but I do need to re-instate them to the proper objects when de-serializing. Can anyone help me with a...
5
6852
by: Gos | last post by:
Hi, It is known that .NET does not allow us to add circular references. Is there a way to workaround this problem by late-binding the objects at run time? Will this create any other problems? One solution to the problem is to re-architect the solution. But, I dont want to do this as there are many modules in the project which are already developed and nearing the release.
6
5081
by: Stephen Robertson | last post by:
We are currently in a dead end with a circular reference issue using vb.net, and are hoping someone might help us resolve it. Idea... We have frmmain calling frmperson (dim f as new frmperson) in search (no record) mode. When the search is executed, frmperson calls frmsearchresult (dim f as new frmsearchresult) which is a listing of persons. From frmsearchresults, frmperson is called (dim f as new frmperson) with the resulting...
2
2826
by: Lapu-Lapu | last post by:
I have authored a web service using ASP 2.0. The web services return objects that use generics and that also contain circular references. Programmatically, everything works well, as long as you use the web service proxy client generated by visual studio. However, the default test harness provided by the .asmx file errors out because it seems to use XmlSerialization and cannot handle circular references. I understand that the...
5
3803
by: Madhur | last post by:
Hello If I define two classes in the same cs file. And in each class, I define the object of other class as a member. Can anyone explain me how .NET or its compiler will resolve this kind of reference since one class would not be compiled unless other is compiled. This is kind of a deadlock. Isnt it ?
2
1859
by: Dansk | last post by:
Hi all, I am currently writing some code that explores assemblies dependencies. I start loading the first assembly with Assmebly.LoadFrom which gives me an Assembly instance. Then, I enumerate the AssemblyNames from the GetReferencedAssemblies() collection.
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10201
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9023
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.