Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Create the order column

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-07-03 : 08:58:41
Quyen writes "How to create the order column in Select statement ?
Ex : Select Name From Test
1 Binh
2 Lam
3 Xuan
4 Nam
......."

dsdeming

479 Posts

Posted - 2002-07-03 : 09:19:47
Look for IDENTITY in BOL.

Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-07-03 : 10:35:52
i've a feeling that the questioner is looking for a solution whereby the recordset contains a rownumber for each record in the recordset...which SQL doesn't support directly....

Go to Top of Page

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-07-03 : 11:01:01
Quyen,

What they are saying here is you can't add it in a select statement like that (unless you really like cursors and union... But thats ugly and very slow). What you want to do is add a column to your table like this

create table test(
Test_ID int identity(1,1),
Name varchar(50)
)

Test_ID will now hold an order number (sql will input this on it's own, you don't have to. Look it up in Books Online for more information). Then your select statement becomes
select Test_ID, Name from test
this will give the results you want.

-----------------------
Take my advice, I dare ya
Go to Top of Page

QuyenLam
Starting Member

1 Post

Posted - 2002-07-03 : 21:05:06
Hi all,
But I want get records in the table follow a condition that a column order for these records?
Ex : Select Name From Test where Name like '%N'
1 Nam
2 Ninh
3 Na
.....

Thanks


Go to Top of Page
   

- Advertisement -