November 26, 2002 03:26 PM

Generating an Incrementing Value from a SELECT Statement

Rating: (0)
SQL Server Magazine
InstantDoc ID #27191

Can I create a simple SELECT statement that generates an IDENTITY-type value by auto-numbering the rows that the SELECT statement retrieves?

Creating a SELECT statement that generates an incrementing value can be difficult because the SELECT statement doesn't permit variable assignment in combination with data retrieval. (This rule exists to prevent you from incrementing a variable within a SELECT statement.) However, if you only want to generate row uniqueness, you can use the NEWID() function that the following SELECT statement shows:

SELECT NEWID(), * FROM dbo.MyTab
If ...

...This article is for paid Professional Members only.

Already a Professional Member? Please log in now:

NOT A PROFESSIONAL MEMBER? YOU CHOOSE:

Professional Membership

Monthly

Annual

VIP Membership

Monthly

Annual

Add a Comment

There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here
GOOGLE LINKS
SPONSORED LINKS
FEATURED LINKS