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 2005 Forums
 Transact-SQL (2005)
 Query issue (Auto Numbered Column)

Author  Topic 

cmspot
Starting Member

44 Posts

Posted - 2008-03-15 : 15:25:05
Hello Guys!I have an important for me and maybe easy question for you...

I want to take the results of a select but i want the first column to be an auto incresement Number...

For example
aa Name Number
1 Alexander Papadopoulos 212222222
2 .... ...
3
4
5

How Can this happen?


I sell my mother in law.Is anybody interested?

TiGGi
Starting Member

29 Posts

Posted - 2008-03-15 : 15:31:46
SET your AA field as Primary Key and make it to be Identity Column
Go to Top of Page

cmspot
Starting Member

44 Posts

Posted - 2008-03-15 : 15:45:36
My Select Is not From One table....

It is a nested query

There is no identity Column



for example
Select c.Custname , c.custid , r.rentdate , r,returndate
From Customers c , rents r
Where c.Custid = r.custid

All I want is an extra auto numeric Column in my select...
Go to Top of Page

TiGGi
Starting Member

29 Posts

Posted - 2008-03-15 : 16:07:25
http://www.sqlteam.com/article/returning-a-row-number-in-a-query
Go to Top of Page

cmspot
Starting Member

44 Posts

Posted - 2008-03-15 : 16:20:37
I know the way Of using a temporary table but the results canot be read from my application (Or maybe i do not know how(VB 2005))....That's why i have a problem.

Is there any other Way than using a temp table?

I sell my mother in law.Is anybody interested?
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-03-15 : 21:50:34
Use the Row_number() function.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-17 : 05:22:54
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

cmspot
Starting Member

44 Posts

Posted - 2008-04-12 : 13:21:54
quote:
Originally posted by madhivanan

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx

Madhivanan

Failing to plan is Planning to fail




Thank you Friend it worked so Well!

I sell my mother in law.Is anybody interested?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-14 : 03:24:47
quote:
Originally posted by cmspot

quote:
Originally posted by madhivanan

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx

Madhivanan

Failing to plan is Planning to fail




Thank you Friend it worked so Well!

I sell my mother in law.Is anybody interested?


Thanks

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -