title: Loop through without Cursor in SQL Server 2005
body: <p>I have a table OrganisationStructure like this:</p>
  
  <pre><code>OrganisationID INT
  ParentOrganisationID INT
  OrganisationName VARCHAR(64)
  
  1 | 0 | Company
  2 | 1 | IT DIVISION 
  3 | 2 | IT SYSTEM BUSINESS UNIT
  4 | 1 | MARKETING DIVISION
  5 | 4 | DONATION BUSINESS UNIT
  </code></pre>
  
  <p>I want to have a query that if the app passing let say <code>OrganisatinID = 1</code> means that it will loop (looking at parent/child) through till end of this table and grap all possible Returned <code>OrganisatioIDs = (1, 2, 3, 4, 5)</code>.</p>
  
  <p>Other if passing <code>OrganisationID = 2</code> then Returned <code>OrganisationID = (2, 3)</code></p>
  
  <p>Other if passing <code>OrganisationID = 3</code>  then Returned <code>OrganisationID = 3</code></p>
  
  <p>Any ideas to do this without cursor?</p>
  
  <p>Thanks</p>