<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Quiz and Video &#8211; Introduction to Hierarchical Query using a Recursive CTE</title>
	<atom:link href="http://blog.sqlauthority.com/2012/05/08/sql-server-quiz-and-video-introduction-to-hierarchical-query-using-a-recursive-cte/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2012/05/08/sql-server-quiz-and-video-introduction-to-hierarchical-query-using-a-recursive-cte/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Fri, 17 May 2013 15:26:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: SQL SERVER &#8211; Weekly Series &#8211; Memory Lane &#8211; #028 &#124; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2012/05/08/sql-server-quiz-and-video-introduction-to-hierarchical-query-using-a-recursive-cte/#comment-472990</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; Weekly Series &#8211; Memory Lane &#8211; #028 &#124; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Sat, 11 May 2013 01:31:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=18546#comment-472990</guid>
		<description><![CDATA[[&#8230;] Quiz and Video – Introduction to Hierarchical Query using a Recursive CTE [&#8230;]]]></description>
		<content:encoded><![CDATA[<p>[&#8230;] Quiz and Video – Introduction to Hierarchical Query using a Recursive CTE [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: arul</title>
		<link>http://blog.sqlauthority.com/2012/05/08/sql-server-quiz-and-video-introduction-to-hierarchical-query-using-a-recursive-cte/#comment-355129</link>
		<dc:creator><![CDATA[arul]]></dc:creator>
		<pubDate>Tue, 02 Oct 2012 11:29:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=18546#comment-355129</guid>
		<description><![CDATA[can u please any one post the query for bottom to top hierarchy ..]]></description>
		<content:encoded><![CDATA[<p>can u please any one post the query for bottom to top hierarchy ..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER &#8211; SQL in Sixty Seconds &#8211; 5 Videos from Joes 2 Pros Series &#8211; SQL Exam Prep Series 70-433 &#171; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2012/05/08/sql-server-quiz-and-video-introduction-to-hierarchical-query-using-a-recursive-cte/#comment-284956</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; SQL in Sixty Seconds &#8211; 5 Videos from Joes 2 Pros Series &#8211; SQL Exam Prep Series 70-433 &#171; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Wed, 16 May 2012 01:31:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=18546#comment-284956</guid>
		<description><![CDATA[[...] [Detailed Blog Post] &#124; [Quiz with Answer] [...]]]></description>
		<content:encoded><![CDATA[<p>[...] [Detailed Blog Post] | [Quiz with Answer] [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chakradhar</title>
		<link>http://blog.sqlauthority.com/2012/05/08/sql-server-quiz-and-video-introduction-to-hierarchical-query-using-a-recursive-cte/#comment-283230</link>
		<dc:creator><![CDATA[Chakradhar]]></dc:creator>
		<pubDate>Wed, 09 May 2012 11:30:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=18546#comment-283230</guid>
		<description><![CDATA[Hi pinal,

I have tried the above example but its not working for me. i tried the first question. but its showing only one record. Here is my defination.

  create table #Employee
(
	EmpID int identity(1,1),
	FirstName varchar(500),
	MgrID int
)
insert into #Employee
(
	FirstName,
	MgrID 
)
values
(
	&#039;David&#039;,
	11
),(&#039;Eric&#039;,11),(&#039;Lisa&#039;,4),(&#039;David&#039;,11),(&#039;John&#039;,4),(&#039;James&#039;,3),(&#039;Sally&#039;,null)
 

select * from #Employee

-----------Emp with recurssion
WITH EmpList AS
(
	SELECT 
		Boss.EmpID, 
		Boss.FirstName,  
		Boss.MgrID,
		1 AS Lvl
	FROM 
		#Employee AS Boss 
	WHERE 
		MgrID IS NULL 
UNION ALL
	SELECT 
		E.EmpID, 
		E.FirstName,  
		E.MgrID, 
		EmpList.Lvl + 1
	FROM 
		#Employee AS E 
		INNER JOIN EmpList ON 
			E.MgrID = EmpList.EmpID
)
SELECT distinct * FROM EmpList order by MgrID asc


Thanks,]]></description>
		<content:encoded><![CDATA[<p>Hi pinal,</p>
<p>I have tried the above example but its not working for me. i tried the first question. but its showing only one record. Here is my defination.</p>
<p>  create table #Employee<br />
(<br />
	EmpID int identity(1,1),<br />
	FirstName varchar(500),<br />
	MgrID int<br />
)<br />
insert into #Employee<br />
(<br />
	FirstName,<br />
	MgrID<br />
)<br />
values<br />
(<br />
	&#8216;David&#8217;,<br />
	11<br />
),(&#8216;Eric&#8217;,11),(&#8216;Lisa&#8217;,4),(&#8216;David&#8217;,11),(&#8216;John&#8217;,4),(&#8216;James&#8217;,3),(&#8216;Sally&#8217;,null)</p>
<p>select * from #Employee</p>
<p>&#8212;&#8212;&#8212;&#8211;Emp with recurssion<br />
WITH EmpList AS<br />
(<br />
	SELECT<br />
		Boss.EmpID,<br />
		Boss.FirstName,<br />
		Boss.MgrID,<br />
		1 AS Lvl<br />
	FROM<br />
		#Employee AS Boss<br />
	WHERE<br />
		MgrID IS NULL<br />
UNION ALL<br />
	SELECT<br />
		E.EmpID,<br />
		E.FirstName,<br />
		E.MgrID,<br />
		EmpList.Lvl + 1<br />
	FROM<br />
		#Employee AS E<br />
		INNER JOIN EmpList ON<br />
			E.MgrID = EmpList.EmpID<br />
)<br />
SELECT distinct * FROM EmpList order by MgrID asc</p>
<p>Thanks,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Conficker</title>
		<link>http://blog.sqlauthority.com/2012/05/08/sql-server-quiz-and-video-introduction-to-hierarchical-query-using-a-recursive-cte/#comment-283192</link>
		<dc:creator><![CDATA[Conficker]]></dc:creator>
		<pubDate>Wed, 09 May 2012 08:25:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=18546#comment-283192</guid>
		<description><![CDATA[love it... very informative.

Thanks]]></description>
		<content:encoded><![CDATA[<p>love it&#8230; very informative.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>
