<?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: SQL Advance Query &#8211; Replace NULL with Previous Non Null value	</title>
	<atom:link href="https://www.dbrnd.com/2019/03/sql-puzzle-sql-advance-query-replace-null-with-previous-non-null-value/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com/2019/03/sql-puzzle-sql-advance-query-replace-null-with-previous-non-null-value/</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Wed, 30 Oct 2019 11:51:16 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>
		By: koustav		</title>
		<link>https://www.dbrnd.com/2019/03/sql-puzzle-sql-advance-query-replace-null-with-previous-non-null-value/#comment-7862</link>

		<dc:creator><![CDATA[koustav]]></dc:creator>
		<pubDate>Wed, 30 Oct 2019 11:51:16 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6105#comment-7862</guid>

					<description><![CDATA[select *,
    (select code from tbl_Values where id in(
    (select max(id) from tbl_Values tbl1 where tbl1.id&#060;=tbl.id and code is not null)))

     from tbl_Values tbl]]></description>
			<content:encoded><![CDATA[<p>select *,<br />
    (select code from tbl_Values where id in(<br />
    (select max(id) from tbl_Values tbl1 where tbl1.id&lt;=tbl.id and code is not null)))</p>
<p>     from tbl_Values tbl</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Phanindra Suripeddi		</title>
		<link>https://www.dbrnd.com/2019/03/sql-puzzle-sql-advance-query-replace-null-with-previous-non-null-value/#comment-7699</link>

		<dc:creator><![CDATA[Phanindra Suripeddi]]></dc:creator>
		<pubDate>Mon, 19 Aug 2019 09:50:45 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6105#comment-7699</guid>

					<description><![CDATA[SELECT Id,Code, IIF(Code IS null, (SELECT TOP 1 b.Code FROM tbl_Values b WHERE b.id&#060;a.id AND b.Code IS NOT NULL ORDER BY b.id DESC),code) Previous_NonNullCode FROM tbl_Values a]]></description>
			<content:encoded><![CDATA[<p>SELECT Id,Code, IIF(Code IS null, (SELECT TOP 1 b.Code FROM tbl_Values b WHERE b.id&lt;a.id AND b.Code IS NOT NULL ORDER BY b.id DESC),code) Previous_NonNullCode FROM tbl_Values a</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Gregor		</title>
		<link>https://www.dbrnd.com/2019/03/sql-puzzle-sql-advance-query-replace-null-with-previous-non-null-value/#comment-7277</link>

		<dc:creator><![CDATA[Gregor]]></dc:creator>
		<pubDate>Tue, 04 Jun 2019 10:59:50 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6105#comment-7277</guid>

					<description><![CDATA[select
*,
(case 
when Code is not null then Code 
else 
(select top 1 innertbl.Code 
from tbl_Values innertbl 
where innertbl.Code is not null
and 
innertbl.Id &#060;= outertbl.Id 
order by Id desc) 
end) 
as Previous_NonNullCode
from tbl_Values outertbl]]></description>
			<content:encoded><![CDATA[<p>select<br />
*,<br />
(case<br />
when Code is not null then Code<br />
else<br />
(select top 1 innertbl.Code<br />
from tbl_Values innertbl<br />
where innertbl.Code is not null<br />
and<br />
innertbl.Id &lt;= outertbl.Id<br />
order by Id desc)<br />
end)<br />
as Previous_NonNullCode<br />
from tbl_Values outertbl</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: HIC		</title>
		<link>https://www.dbrnd.com/2019/03/sql-puzzle-sql-advance-query-replace-null-with-previous-non-null-value/#comment-6954</link>

		<dc:creator><![CDATA[HIC]]></dc:creator>
		<pubDate>Sat, 06 Apr 2019 20:00:41 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6105#comment-6954</guid>

					<description><![CDATA[select 
  a.id
, a.code 
, nvl(a.code, (select b.code from tbl_Values b where b.id = (select max(c.id) from tbl_Values c where c.id &#060; a.id and c.code is not null)))
from 
  tbl_Values a
order by id]]></description>
			<content:encoded><![CDATA[<p>select<br />
  a.id<br />
, a.code<br />
, nvl(a.code, (select b.code from tbl_Values b where b.id = (select max(c.id) from tbl_Values c where c.id &lt; a.id and c.code is not null)))<br />
from<br />
  tbl_Values a<br />
order by id</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Ram Chekuri		</title>
		<link>https://www.dbrnd.com/2019/03/sql-puzzle-sql-advance-query-replace-null-with-previous-non-null-value/#comment-6942</link>

		<dc:creator><![CDATA[Ram Chekuri]]></dc:creator>
		<pubDate>Mon, 01 Apr 2019 00:34:44 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6105#comment-6942</guid>

					<description><![CDATA[with x as (
select *, sum(case when code is null then 0 else 1 end)  over (order by id) rnk
from tbl_values
)

select id, code, max(code) over (partition by rnk)
from x]]></description>
			<content:encoded><![CDATA[<p>with x as (<br />
select *, sum(case when code is null then 0 else 1 end)  over (order by id) rnk<br />
from tbl_values<br />
)</p>
<p>select id, code, max(code) over (partition by rnk)<br />
from x</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
