Thursday, May 23, 2013

How we will generate Row Numbers from a table in sql server


I have table which contains the following information, I didn't have row numbers, just see the below image


If you want row numbers for that table just you need to add some logic to you query, that should be look like this
select Row_Number() over (order by PID)as RowNum,PID,ProjectName,Statuss,FromDate,ToDate from tbProjects

Then the output will look like below image
when you observer the above image you will find the row number.

It will be used, when you want to display the data in the front end, at the same time you will bind the row numbers fro front end. 

See the above image, both column number and project name is displaying. This is the case when you want to  display column numbers in the gridview with other stuff.


No comments:

Post a Comment