user ROW_NUMBER Over (order by fanSerialNo) as Srno It will gve u the Sr no of the Row.But there must be some unique key or group of keys so that we can get the rownumber according to that particular key
On Fri, Sep 4, 2009 at 11:24 PM, Davaasuren Nyamjav <[email protected]>wrote: > Using Row_number() function or insert current table data to dynamic table > with is column would be most appropriate way to do this. > > > Thanks, > > > > > On Fri, Sep 4, 2009 at 10:33 AM, Abul Hasan Lakhani < > [email protected]> wrote: > >> you can use ROW_NUMBER() function with OVER clause such as: >> USE AdventureWorks; >> GO >> SELECT c.FirstName, c.LastName >> ,ROW_NUMBER() OVER(ORDER BY SalesYTD DESC) AS 'Row Number' >> ,s.SalesYTD >> FROM Sales.SalesPerson s >> INNER JOIN Person.Contact c >> ON s.SalesPersonID = c.ContactID >> >> for more details check SQL Server books online >> >> Regards, >> >> Abul Hasan >> >> 2009/9/4 Andrew Badera <[email protected]> >> >> >>> There is no such thing. >>> >>> You can get the row's primary key value. You can use ROW_NUMBER in >>> your statements to arbitrarily assign a row number, but there's no >>> intrinsic "row number" by default. >>> >>> You can also use "SELECT TOP 5" to get the first 5 results of a query, >>> and use the fifth result .. >>> >>> ∞ Andy Badera >>> ∞ +1 518-641-1280 >>> ∞ This email is: [ ] bloggable [x] ask first [ ] private >>> ∞ Google me: >>> http://www.google.com/search?q=(andrew+badera)+OR+(andy+badera)<http://www.google.com/search?q=%28andrew+badera%29+OR+%28andy+badera%29> >>> >>> >>> >>> On Fri, Sep 4, 2009 at 9:12 AM, san<[email protected]> wrote: >>> > How can i get the row number in which record is stored in sql server. >>> > >>> > Example: suppose if record is stored in fifth row i want output as 5. >>> > >>> > Thanks! >>> > >>> > >>> >> >> >> >> -- >> Abul Hasan Lakhani >> > > > > -- > David Nyamjav > --------------------------------------------------- > Tel: 213-453-3248 > Email: [email protected] > -- Harpreet Singh (¨`•.•´¨) Always `•.¸(¨`•.•´¨) Keep (¨`•.•´¨)¸.•´ Smiling! `•.¸.•´ ੴ ਵਾਹਿਗੁਰੂ ਜੀ ਕਾ ਖਾਲਸਾ ਵਾਹਿਗੁਰੂ ਜੀ ਕੀ ਫਤਿਹ.ੴ .
