title: Account Hierarchy Salesforce Accounts - SQL Server
body: <p>I am working on a report that uses Salesforce Datawarehouse. Essentially, given a particular account, I need to find the hierarchy just for that. This could be at any level down but it HAS to get ALL the NODES. </p>
  
  <p>The following is what I have: </p>
  
  <pre><code>WITH tree (id, parentid, level, name) as 
  (
     SELECT id, parentid, 0 as level, name
     FROM accounts
     WHERE (parentid IS NULL 
     AND recordtypeid NOT IN ('012G0000001NLJSIA4', '012G0000001NLKGIA4'))
  
     UNION ALL
  
     SELECT c2.id, c2.parentid, tree.level + 1, c2.name
     FROM accounts c2 
       INNER JOIN tree ON tree.id = c2.parentid
       AND recordtypeid NOT IN ('012G0000001NLJSIA4', '012G0000001NLKGIA4')
  )
  SELECT *
  FROM tree
  </code></pre>
  
  <p>What I really should be able to do is provide an account parameter, whose details I am looking for and have it only return the hierarchy for that. </p>
  
  <p>Any Help? I have been struggling this with for a couple of days now. </p>