SELECT WITH ONE FIELD THAT INCREMENTS

  • Hi,

    Maybe a bit difficult to explain, but here it is: I need a select statement, with one field that increments.

    For example:

    SELECT name, country FROM persons WHERE lastname='Jones'

    would result in:

    [font="Courier New"]

    John USA

    Pete USA

    Mary Canada

    [/font]

    I need something like:

    SELECT cntr, name, country FROM persons WHERE lastname='Jones'

    would result in:

    [font="Courier New"]

    1 John USA

    2 Pete USA

    3 Mary Canada

    [/font]

    Anyone?

    Thanks!

  • you could use the row_number function to do this for you

    SELECT ROW_NUMBER() OVER(ORDER BY name) as [cntr], name, country FROM persons WHERE lastname='Jones'

    http://msdn.microsoft.com/en-us/library/ms186734.aspx[/b]

  • tHX!!!!!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply