﻿<?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 / SQL Server Newbies  / Query Help / 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 02:12:18 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Query Help</title><link>http://www.sqlservercentral.com/Forums/Topic1423396-1292-1.aspx</link><description>that's awesome laurie thanks a ton :)</description><pubDate>Sun, 24 Feb 2013 10:46:11 GMT</pubDate><dc:creator>irfanullah</dc:creator></item><item><title>RE: Query Help</title><link>http://www.sqlservercentral.com/Forums/Topic1423396-1292-1.aspx</link><description>Something like this should do it:[code="sql"]--i have table with following structure.--SELECT SaleID, vender_inv, Code, cDate--FROM SaleMain--i want to fetch last two invoice against each code.--where saleid is auto incremented and cdate as well to get last --invoice.select *from(select SaleId, Vender_Inv, Code, cDate,ROW_NUMBER() over (partition by Code order by cDate Desc) as RowNumberFROM SaleMain ) Awhere A.RowNumber &amp;lt; 3[/code]</description><pubDate>Sun, 24 Feb 2013 10:27:34 GMT</pubDate><dc:creator>laurie-789651</dc:creator></item><item><title>RE: Query Help</title><link>http://www.sqlservercentral.com/Forums/Topic1423396-1292-1.aspx</link><description>You might want to look into the CROSS APPLY syntax (use it to get the Top 2  vender_inv ORDER BY SaleID DESC) together with a cte or subquery to return all distinct code values.</description><pubDate>Sun, 24 Feb 2013 03:10:07 GMT</pubDate><dc:creator>LutzM</dc:creator></item><item><title>Query Help</title><link>http://www.sqlservercentral.com/Forums/Topic1423396-1292-1.aspx</link><description>i have table with following structure.SELECT      SaleID, vender_inv, Code, cDateFROM         SaleMaini want to fetch last two invoice against each code.where saleid is auto incremented and cdate as well to get last invoice. help will be really appreciated.</description><pubDate>Sat, 23 Feb 2013 23:26:31 GMT</pubDate><dc:creator>irfanullah</dc:creator></item></channel></rss>