• syedathariqbal (5/10/2013)


    Hi All,

    Need help on some recursive Data. I would need to get 4 records out of below available If I pass value 395. Since, for 395, COlD (Child of ColA) has value 394. Again we check ColaA for 394 and find the corresponding value in ColD which is 347. Again in ColA 347 corresponds to 0 value in ColD. Total of 4 records.

    ColA ColB ColC ColD ColE ColF

    347 AA 25 0 0 0

    362 BB 25 347 0 50

    363 CC 25 362 0 51

    364 DD 25 347 0 50

    365 EE 25 364 0 51

    367 FF 25 365 0 54

    369 GG 25 347 0 50

    373 HH 25 347 0 50

    374 II 25 373 0 51

    375 JJ 25 374 0 54

    376 KK 25 374 0 54

    394 LL 25 347 0 50

    395 MM 25 394 0 51

    I beleive Using While loop this can be done. Any suggestions ?

    Sure: set this table up as a CREATE TABLE & INSERTs to populate it, test that the script executes without errors, then post it here.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden