Click here to Skip to main content
15,891,839 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I have one query and it's out put is like this.
My database in SQL Server -2000 .

Select Name from table_name

Out Put
========
Name
======
Test1
Test2
Test3
Test4

But I want this types of out put.

Out Put
========
ID   Name
=========
1    Test1
2    Test2
3    Test3
4    Test4



Thanks
Posted

If the Id is a field in the table then:
SQL
Select Id, Name from table_name

If you mean that you want a row number in the result and the row number is defined based on the order of names then the query would look something like:
SQL
select row_number() over (order by name) as id, Name from table_name
 
Share this answer
 
v2
you just add a column ID and make it to auto-increment.

then write this query:
<br />
Select ID,Name from table_name


hope it helps :)
 
Share this answer
 
if you are looking for store values with corresponding increasing order by number. then you can use IDENTITY as shown given below
create table Table_Name(ID int IDENTITY(1,1),Name varchar(10)) 


After inserting values as you mentioned Test1 to Test4 or something else it will give out put as you want.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900