Creating an ID to go along with my data when querying SQL Server

I have a little problem when querying data. I have a table that looks like this:

Value1       Value2
ABC          123 
BCD          123
DCE          123
EFG          123

What I’m hoping to do is, basically only select VALUE1 from this table, however, I’d like to assign an ID to go along with each value…

  • Error during loading of SSIS package
  • Content download from within a Windows client - Best Practices
  • I am having trouble inserting into my database with c#
  • SQL Server error 1934 occurs on INSERT to table with computed column PHP/PDO
  • How do I have a check constraint that refers to another table?
  • Desired end result

    ID      Value1
    1       ABC
    2       BCD
    3       DCE
    4       EFG

    Is something like that possible? I’d hope to have the end result to be in alphabetical order and ID’s assigned based in ASCENDING order. Also, would hope that this query can be in place even if more VALUE1 values are added in the table (dynamic)

    Any ideas?

    One Solution collect form web for “Creating an ID to go along with my data when querying SQL Server”

    You can use window function row_number while selecting:

    select row_number() over (
            order by value1
            ) as id,
    from your_table;
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.