﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / help regarding selecting the maximum value / 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>Mon, 20 May 2013 12:53:21 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: help regarding selecting the maximum value</title><link>http://www.sqlservercentral.com/Forums/Topic1405382-392-1.aspx</link><description>What do you want to make dynamic?But yes if you write dynamic SQL then you can make it dynamic.</description><pubDate>Thu, 10 Jan 2013 06:48:00 GMT</pubDate><dc:creator>anthony.green</dc:creator></item><item><title>RE: help regarding selecting the maximum value</title><link>http://www.sqlservercentral.com/Forums/Topic1405382-392-1.aspx</link><description>Perfect !!! is it possible to come up with some dynamic query  here we are selecting the rows based on the row number(rn)</description><pubDate>Thu, 10 Jan 2013 06:45:46 GMT</pubDate><dc:creator>Smash125</dc:creator></item><item><title>RE: help regarding selecting the maximum value</title><link>http://www.sqlservercentral.com/Forums/Topic1405382-392-1.aspx</link><description>A good case for ROW_NUMBER()[code="sql"]drop table #datacreate table #data(contactid int,totaldue money,rn int,maxrn int)insert into #dataselect 1, 49846.693, 1, 1union allselect 1, 43214.9511, 2, 2union allselect 2, 43962.7901, 1, 1union allselect 2, 42123.1691, 2, 2union allselect 3, 89409.6319, 1, 1union allselect 3, 82078.0355, 2, 2union allselect 4, 27162.5876, 1, 1select * from #data;with cte as(select	ROW_NUMBER() OVER(PARTITION BY ContactID ORDER BY RN DESC) AS RowNum,	*FROM	#data)select * from cte where rownum = 1[/code]</description><pubDate>Thu, 10 Jan 2013 06:36:36 GMT</pubDate><dc:creator>anthony.green</dc:creator></item><item><title>help regarding selecting the maximum value</title><link>http://www.sqlservercentral.com/Forums/Topic1405382-392-1.aspx</link><description>Please find the test data as below.finding tough to come up with logic.Would appreciate greatly if some could helpcreate table #data(contactid int,totaldue money,rn int,maxrn int)select 1,    49846.693,    1,    1union allselect 1,    43214.9511,    2,    2union allselect 2,    43962.7901,    1,    1union allselect 2,    42123.1691,    2,    2union allselect 3,    89409.6319,    1,    1union allselect 3,    82078.0355,    2,    2union allselect 4,    27162.5876,    1,    1I want the o/p likecontactid,totaldue,rn,maxrn1,43214,2,22,42123.1691,2,23,82078.0355,2,24,27162.5876,1,1</description><pubDate>Thu, 10 Jan 2013 06:29:53 GMT</pubDate><dc:creator>Smash125</dc:creator></item></channel></rss>