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. Help required for CTE

Help required for CTE

Scheduled Pinned Locked Moved Database
cssdatabasehelptutorialquestion
1 Posts 1 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.
  • Z Offline
    Z Offline
    Zafar Sultan
    wrote on last edited by
    #1

    This is my stored procedure ALTER PROCEDURE TeamStructure ( @rootid int ) AS WITH MyTeam AS ( SELECT *, [Name] AS ParentName, 0 AS TeamLevel FROM tbl_team WHERE ParentID =@rootid UNION ALL SELECT Fam.*,MyTeam.Name AS ParentName, TeamLevel + 1 FROM tbl_team AS Fam INNER JOIN MyTeam ON Fam.ParentID = MyTeam.ID) SELECT * FROM MyTeam It will return the complete hierarchical records. Level 0 will have root member Level 1 will have 2 members Level 2 willhave 4 members Level 3 will have 8 members or if level =n members= 2^n I need to perform the following operation: for any level if members are less than 2^n the iteration should stop and return the number of members on that level and the number of level For example if the number of members on level 4 are 12 The procedure should stop and return level :4 Members :12 but if the number of members on nth level is exactly 2^n the iteration must look for the next level Can anyone modify this procedure and help me please? TIA

    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