.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

How to get row Id of a table?

Posted By: Jean Paul     Posted Date: November 10, 2010    Points:2   Category :Sql Server
I do have a table without any id columns like

Name
Address
Age

etc.

It contains many records and I need to update a particular record.
How I can find the row number (any internal row number by sql server)?

Responses
Author: Sajid P K             
Posted Date: November 11, 2010     Points: 5   

Hi,

You can use ROW_NUMBER() function to get Row id. Note That it is only aviliable in Sql server 2005 & 2008.

Please see the sample Code below...



SELECT ROW_NUMBER() OVER (ORDER BY Name ASC) AS ROWID, * FROM TableX



Regards,
Sajid P K

Author: Jean Paul             
Posted Date: November 11, 2010     Points: 5   

Thanks Sajid... Can you please share the code for updating the Record with rownumber=3

Jean Paul http://jeanpaulva.com/
Author: Sajid P K             
Posted Date: November 11, 2010     Points: 5   
Author: Jean Paul             
Posted Date: November 11, 2010     Points: 5   

Thank You Sajid.. I will try that one.

Jean Paul http://jeanpaulva.com/
Author: Syed Shakeer Hussain             
Posted Date: November 12, 2010     Points: 5   

Hi,



with CTE as(select row_number() over(partition by name order by name) row,name,Address,Age from tablename)
update from CTE where row=3




Author: NITIN             
Posted Date: November 24, 2010     Points: 5   

Hi All

I tried to run this query but it was not working actually


can you please suggest on this


NITIN



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend