Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to check for circular referencing

Author  Topic 

Sanette
Starting Member

3 Posts

Posted - 2002-07-19 : 03:08:59
It would be great if someone can help me out on this one.

I have the following data:

ITEMFROM ITEMTO ALLOWED?
ItemA ItemB Yes
ItemA ItemC Yes
ItemB ItemD Yes
ItemC ItemD Yes
ItemD ItemB No
ItemD ItemA No
ItemE ItemB Yes
ItemF ItemB Yes
ItemF ItemC Yes
ItemA ItemA No

My current code looks like this:

IF (SELECT COUNT(*)
FROM tbl_SupercessionHeader
WHERE ItemMasterIDFrom = @iFromItemMasterID ) > 0
BEGIN
RETURN
END

IF (SELECT COUNT(*)
FROM tbl_SupercessionHeader
WHERE ItemMasterIDFrom = @iToItemMasterID ) > 0
BEGIN
RAISERROR ('Item has circular referencing',16,1)
RETURN
END

The problem with the code is that if an Item is already superceded it cannot be superceded again, e.g. ItemA --> ItemB, ItemA --> ItemC will not be allowed (and it should).

Any ideas?????

   

- Advertisement -