﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Suresh Maganti / Article Discussions / Article Discussions by Author  / Dealing with Incomplete Data - A T-SQL Puzzle 1 / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 20 Jun 2013 03:04:24 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Dealing with Incomplete Data - A T-SQL Puzzle 1</title><link>http://www.sqlservercentral.com/Forums/Topic1209814-260-1.aspx</link><description>[quote][b]Jeff Moden (11/22/2011)[/b][hr][quote][b]Suresh Kumar Maganti (11/22/2011)[/b][hr]The Query cost (relative to the batch) was 17% for the one in the article. The same for the alternative version was 83%. [/quote]The query cost relative to the batch actually doesn't mean much.  It's quite easy to write queries that doe the same thing where one will be 100% of the batch and the other will be 0% and yet, when you run them, the 0% query take take several seconds where the 100% query runs so fast it almost isn't measureable.[/quote]I'm relatively new to SQL tuning. I haven't heard of that happening. Can you explain how or why that might happen? Thank you.</description><pubDate>Wed, 23 Nov 2011 09:43:40 GMT</pubDate><dc:creator>floresg2</dc:creator></item><item><title>RE: Dealing with Incomplete Data - A T-SQL Puzzle 1</title><link>http://www.sqlservercentral.com/Forums/Topic1209814-260-1.aspx</link><description>[quote][b]Suresh Kumar Maganti (11/22/2011)[/b][hr]The Query cost (relative to the batch) was 17% for the one in the article. The same for the alternative version was 83%. [/quote]The query cost relative to the batch actually doesn't mean much.  It's quite easy to write queries that doe the same thing where one will be 100% of the batch and the other will be 0% and yet, when you run them, the 0% query take take several seconds where the 100% query runs so fast it almost isn't measureable.</description><pubDate>Tue, 22 Nov 2011 22:07:56 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Dealing with Incomplete Data - A T-SQL Puzzle 1</title><link>http://www.sqlservercentral.com/Forums/Topic1209814-260-1.aspx</link><description>Hi Chris,           Thanks for the nice feedback.            I appreciate and like the solution you have provided. Your code is shorter too for which I like it even more.           Just to see from a performance perspective, I tried executing both the code snippets in the same batch. The Query cost (relative to the batch) was 17% for the one in the article. The same for the alternative version was 83%.            Notwithstanding the minor performance difference since the data volume in the code is very limited, I still like your code for its brevity.                                                           ------Thanks and Best Regards,                                                                      Suresh.</description><pubDate>Tue, 22 Nov 2011 15:04:42 GMT</pubDate><dc:creator>Suresh Kumar Maganti</dc:creator></item><item><title>RE: Dealing with Incomplete Data - A T-SQL Puzzle 1</title><link>http://www.sqlservercentral.com/Forums/Topic1209814-260-1.aspx</link><description>Dear Sir,          This is really very good alternative solution.           Can't I delete the selected bad rows in the same statement like this....[code="sql"]WITH OrderedData AS (         SELECT                 Seq_No,                 cdata,                 x.RowID,                 rn = ROW_NUMBER() OVER(PARTITION BY x.RowID ORDER BY p.Seq_No)            FROM #Test_Table p         CROSS APPLY (                SELECT RowID = MAX(Seq_No)                 FROM #Test_Table                 WHERE CData = '*********************************************' AND Seq_No &amp;lt;= p.Seq_No         ) x ) Delete from t output deleted.Seq_No, deleted.CData into dbo.Test_Table_Bad_Records FROM OrderedData t WHERE t.RowID IN (         SELECT r1.RowID         FROM OrderedData r1         INNER JOIN OrderedData r2                 ON r2.RowID = r1.RowID AND r2.rn = r1.rn + 1         WHERE r1.CData = 'RateQuote' AND r2.CData = ' ')[/code]Thanks..</description><pubDate>Tue, 22 Nov 2011 04:02:41 GMT</pubDate><dc:creator>aspiring_dba</dc:creator></item><item><title>RE: Dealing with Incomplete Data - A T-SQL Puzzle 1</title><link>http://www.sqlservercentral.com/Forums/Topic1209814-260-1.aspx</link><description>Dear Sir,       Very good use of CTE. I learn to know the real strength of CTE after reading this article.        The best thing about CTE is that it keeps the readability of the code. Its very easy to understand the approach of a developer in the solutions based on CTE feature.       and also the real life Scenario u have given here helps me to understand the kind of problems and real world situation that can arise before DBA.        I am new in this forum and I want to be good DBA.         Now i know that i am going to learn a lot here.Thanks...</description><pubDate>Tue, 22 Nov 2011 03:06:48 GMT</pubDate><dc:creator>aspiring_dba</dc:creator></item><item><title>RE: Dealing with Incomplete Data - A T-SQL Puzzle 1</title><link>http://www.sqlservercentral.com/Forums/Topic1209814-260-1.aspx</link><description>What a really nicely written article to start the day off with, very enjoyable.Suresh, have you tried using CROSS APPLY to partition the rows into "records" as an alternative to calculating the upper and lower bound? You can then sequence the rows within each "record", then by joining the result to itself (staggered by one row), identification of missing data is quite simple:[code="sql"];WITH OrderedData AS (	 SELECT 		Seq_No, 		cdata, 		x.RowID, 		rn = ROW_NUMBER() OVER(PARTITION BY x.RowID ORDER BY p.Seq_No)   	 FROM #Test_Table p	 CROSS APPLY (		SELECT RowID = MAX(Seq_No) 		FROM #Test_Table 		WHERE CData = '*********************************************' AND Seq_No &amp;lt;= p.Seq_No	 ) x ) SELECT t.* FROM OrderedData t WHERE t.RowID IN (	 SELECT r1.RowID	 FROM OrderedData r1	 INNER JOIN OrderedData r2 		ON r2.RowID = r1.RowID AND r2.rn = r1.rn + 1	 WHERE r1.CData = 'RateQuote' AND r2.CData = ' ')[/code]I wonder how this would perform against the original?CheersChrisM</description><pubDate>Tue, 22 Nov 2011 02:28:17 GMT</pubDate><dc:creator>ChrisM@Work</dc:creator></item><item><title>Dealing with Incomplete Data - A T-SQL Puzzle 1</title><link>http://www.sqlservercentral.com/Forums/Topic1209814-260-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/articles/T-SQL/74088/"&gt;Dealing with Incomplete Data - A T-SQL Puzzle 1&lt;/A&gt;[/B]</description><pubDate>Mon, 21 Nov 2011 21:28:08 GMT</pubDate><dc:creator>Suresh Kumar Maganti</dc:creator></item></channel></rss>