I want to validate where each parent intermediary is also a parent to itself?

  • Hi All',

    I want to validate where each parent intermediary is also a parent to itself. So this query should return invalid parents in SELECT If table has any.

    --===== Create the test table

    CREATE TABLE Intermediary

    (

    IntermediaryPK INT ,

    IntermediaryID NVARCHAR(20),

    IntermediaryName NVARCHAR(200),

    IntermediaryTypeID NVARCHAR(1),,

    ParentIntermediaryID NVARCHAR(20),

    IntermediaryTypePK TINYINT,

    ParentIntermediaryPK INT

    GrandParentIntermediaryPK INT

    GrandParentIntermediaryID NVARCHAR(20)

    )

    == Insert the test data into the test table

    INSERT INTO Intermediary

    (IntermediaryPK, IntermediaryID, IntermediaryName, IntermediaryTypeID, ParentIntermediaryID, IntermediaryTypePK, ParentIntermediaryPK, GrandParentIntermediaryPK, GrandParentIntermediaryID)

    SELECT '552',200244584261,'A''1''201841943403''1' '6459''6459''201841943403'UNION ALL

    SELECT '553','200983879092','B''1''200707895681''1' '6462''6459''200707895681'UNION ALL

    SELECT '554','200925413387','C''1''200707895681''1' '6462''6462''200707895681'UNION ALL

    SELECT '555','200472620781','D''1''200707895681''1''6462' '6462''200707895681'UNION ALL

    SELECT '556','201902784325','E''1''200707895681''1''6462' '6462''200707895681'UNION ALL

    SELECT '557','201874832909','F''1''200707895681''1''566' '6462''200707895681'UNION ALL

    SELECT '558','201264024229','G''1''200707895681''1' '566''6462''200707895681'UNION ALL

    SELECT '559','201725870455','H''1''201062751762''1''566''6462''200707895681'

  • Please don't create more than one thread for the same topic. It just fragments replies and will delay resolution of your issue.

    Direct all your future posts to the original thread

    http://www.sqlservercentral.com/Forums/Topic1456981-392-1.aspx


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply