<?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/"
	
	>
<channel>
	<title>
	Comments on: SQL Puzzle: Use Recursive CTE, and list out the Years from Dates	</title>
	<atom:link href="https://www.dbrnd.com/2018/05/sql-puzzle-use-recursive-cte-and-list-out-the-years-from-dates/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com/2018/05/sql-puzzle-use-recursive-cte-and-list-out-the-years-from-dates/</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Wed, 17 Apr 2019 09:59:08 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>
		By: HIC		</title>
		<link>https://www.dbrnd.com/2018/05/sql-puzzle-use-recursive-cte-and-list-out-the-years-from-dates/#comment-6984</link>

		<dc:creator><![CDATA[HIC]]></dc:creator>
		<pubDate>Wed, 17 Apr 2019 09:59:08 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7499#comment-6984</guid>

					<description><![CDATA[pl/sql version:

with years(fyear) as (
  select extract(year from to_date(&#039;01.01.2010&#039;, &#039;dd.mm.yyyy&#039;)) as fyear from dual
  union all
  select fyear + 1 from years where fyear &#060; extract(year from to_date(&#039;01.01.2018&#039;, &#039;dd.mm.yyyy&#039;))
)
select * from years;]]></description>
			<content:encoded><![CDATA[<p>pl/sql version:</p>
<p>with years(fyear) as (<br />
  select extract(year from to_date(&#8216;01.01.2010&#8217;, &#8216;dd.mm.yyyy&#8217;)) as fyear from dual<br />
  union all<br />
  select fyear + 1 from years where fyear &lt; extract(year from to_date(&#039;01.01.2018&#039;, &#039;dd.mm.yyyy&#039;))<br />
)<br />
select * from years;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Prakash Annadurai		</title>
		<link>https://www.dbrnd.com/2018/05/sql-puzzle-use-recursive-cte-and-list-out-the-years-from-dates/#comment-6845</link>

		<dc:creator><![CDATA[Prakash Annadurai]]></dc:creator>
		<pubDate>Mon, 14 Jan 2019 00:15:24 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7499#comment-6845</guid>

					<description><![CDATA[Here is my solution

Drop table if exists #Records
Create table #Records
(YearColumn date)

INSERT INTO #Records
VALUES
 (&#039;2004-01-01&#039;)
,(&#039;2009-01-01&#039;)
,(&#039;2012-01-01&#039;)
,(&#039;2013-01-01&#039;)
,(&#039;2016-01-01&#039;)
,(&#039;2017-01-01&#039;)

With Res as
(
SELECT   yearColumn, lead(YearColumn) over(Order by YearColumn) as NextVal
From #Records
)
select Year(Dateadd(year,1,YearColumn)),Year(Dateadd(year,-1,NextVal)) 
from Res
Where datediff(year,YearColumn,NextVal)&#062;1
Order by YearColum]]></description>
			<content:encoded><![CDATA[<p>Here is my solution</p>
<p>Drop table if exists #Records<br />
Create table #Records<br />
(YearColumn date)</p>
<p>INSERT INTO #Records<br />
VALUES<br />
 (&#8216;2004-01-01&#8217;)<br />
,(&#8216;2009-01-01&#8217;)<br />
,(&#8216;2012-01-01&#8217;)<br />
,(&#8216;2013-01-01&#8217;)<br />
,(&#8216;2016-01-01&#8217;)<br />
,(&#8216;2017-01-01&#8217;)</p>
<p>With Res as<br />
(<br />
SELECT   yearColumn, lead(YearColumn) over(Order by YearColumn) as NextVal<br />
From #Records<br />
)<br />
select Year(Dateadd(year,1,YearColumn)),Year(Dateadd(year,-1,NextVal))<br />
from Res<br />
Where datediff(year,YearColumn,NextVal)&gt;1<br />
Order by YearColum</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Dinesh		</title>
		<link>https://www.dbrnd.com/2018/05/sql-puzzle-use-recursive-cte-and-list-out-the-years-from-dates/#comment-6463</link>

		<dc:creator><![CDATA[Dinesh]]></dc:creator>
		<pubDate>Sat, 26 May 2018 08:08:40 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7499#comment-6463</guid>

					<description><![CDATA[Declare @StartDate DateTime,@EndDate DateTime;
Set @StartDate=&#039;20100101&#039;
Set @EndDate=&#039;20180101&#039;

;
WITH CTE
As
(Select Year(Convert(DateTime,@StartDate,112)) As YearOfBIll
Union All
Select YearOfBIll+1
From CTE
Where YearOfBill&#060;Year(Convert(DateTime,@EndDate,112))
)
Select * From CTE]]></description>
			<content:encoded><![CDATA[<p>Declare @StartDate DateTime,@EndDate DateTime;<br />
Set @StartDate=&#8217;20100101&#8242;<br />
Set @EndDate=&#8217;20180101&#8242;</p>
<p>;<br />
WITH CTE<br />
As<br />
(Select Year(Convert(DateTime,@StartDate,112)) As YearOfBIll<br />
Union All<br />
Select YearOfBIll+1<br />
From CTE<br />
Where YearOfBill&lt;Year(Convert(DateTime,@EndDate,112))<br />
)<br />
Select * From CTE</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
