Wednesday, March 21, 2012

How to create a select statement with an increasement variable?

Example:

Select icount + 1 as icount from table

or

Select counter() as icount from table

The above is wrong ...just a sample to show what I am trying to accomplish.

Is there a function in SQL statement? Thanks.No, this unfortunately is not possible.

The solution I've seen to this is to create either a #Temp table (or better, a table variable) with an Identity column and the other columns you need, and then INSERT your resultset into it. This will give you the incrementing column you are looking for.

Alternately, add this counter in the front end (on your ASP.NET page).

Terri|||The reason I can't add the counter in the front end because I am doing paging.

Thanks for your help. I think I will create #temp table to solve my problem.sql

No comments:

Post a Comment