Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Input required..need help:recursive procedure & container logic

Input required..need help:recursive procedure & container logic

Scheduled Pinned Locked Moved Database
dockerhelptutorialannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ramina sen
    wrote on last edited by
    #1

    I want to write a procedure 1.find the child of a parent recursively till we do not find any child. 2.Then collect all the child in get in step one and update the value of name of all the child-->second procedure approach: 1. write a procedure to take all the parent as input 2. write a procedure to find child recursively till we do not find any child further e.g 1:parent 1.1 child now consider 1.1 as parent and find child e.g 1.2 recursively call and collect and then update all the child name proc 2: simple procedure with update where id ("child we got previously ") I got the logic but do not know how to call recursively the procedure and hold the values of child any sample code or input is highly appreciated!!! Thanks, Ramina

    L M 2 Replies Last reply
    0
    • R ramina sen

      I want to write a procedure 1.find the child of a parent recursively till we do not find any child. 2.Then collect all the child in get in step one and update the value of name of all the child-->second procedure approach: 1. write a procedure to take all the parent as input 2. write a procedure to find child recursively till we do not find any child further e.g 1:parent 1.1 child now consider 1.1 as parent and find child e.g 1.2 recursively call and collect and then update all the child name proc 2: simple procedure with update where id ("child we got previously ") I got the logic but do not know how to call recursively the procedure and hold the values of child any sample code or input is highly appreciated!!! Thanks, Ramina

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      ramina sen wrote:

      any sample code or input is highly appreciated!!!

      MSDN[^], see the heading "Using a recursive CTE in an UPDATE statement". More info, also on MSDN[^] :)

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      1 Reply Last reply
      0
      • R ramina sen

        I want to write a procedure 1.find the child of a parent recursively till we do not find any child. 2.Then collect all the child in get in step one and update the value of name of all the child-->second procedure approach: 1. write a procedure to take all the parent as input 2. write a procedure to find child recursively till we do not find any child further e.g 1:parent 1.1 child now consider 1.1 as parent and find child e.g 1.2 recursively call and collect and then update all the child name proc 2: simple procedure with update where id ("child we got previously ") I got the logic but do not know how to call recursively the procedure and hold the values of child any sample code or input is highly appreciated!!! Thanks, Ramina

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        Is there some reason for doing this recursively, you should be able to achieve a simple update in one sql statement using an inner join!

        Never underestimate the power of human stupidity RAH

        R 1 Reply Last reply
        0
        • M Mycroft Holmes

          Is there some reason for doing this recursively, you should be able to achieve a simple update in one sql statement using an inner join!

          Never underestimate the power of human stupidity RAH

          R Offline
          R Offline
          ramina sen
          wrote on last edited by
          #4

          correct, but as I have mention my inner query is giving me only parent but I want to make use of the result of the inner query again as input till I did not find any child ,so I am using procedure as I have to collect all the parent I get from the inner query and then update the outer query using the inner query result.it is the requirement what I want to achive, e.g update table A set A.a as "xyz" //here I will get t where A.id in ( select A.child_id from A,B,C --I get the child by passing parent as input and again consider the child as parent and find the child where A.id= b.id b.name = x and A.prent_id = ? //few join condtion here ) e.g input 1 result 1.1 input 1.1 result 1.1.1 input 1.1.1 result 1.1.1.1 update A where A.id in ('1.1','1.1.1','1.1.1.1')--here I want to use a container and make use of it Hope you get my intention now ..Thanks for your response.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups