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)
 Select Identity column

Author  Topic 

Babli
Yak Posting Veteran

53 Posts

Posted - 2007-03-10 : 05:46:12
Hi,

I have a Stored Proc that does a union of two tables and sorts it by a column.

I want to add a column for Serial No while fetching the records.

I tried Identity(int,1,1) but I realised that I need another table as it needs an INTO clause.

Should I create another table with the same schema as the existing table ??

Is there any other way I can insert a column for serial no??

Please note that I cannot use Temp tables.

Help needed.
Thanks in advance.

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-03-10 : 09:53:26
What do you mean by serial number? do you mean just an increasing integer, like a row count number?

if so, check out the ROW_NUMBER() function, new in 2005: http://msdn2.microsoft.com/en-us/library/ms186734.aspx

see also RANK() and DENSE_RANK()


www.elsasoft.org
Go to Top of Page

Babli
Yak Posting Veteran

53 Posts

Posted - 2007-03-10 : 12:51:20
Yes I mean sequential numbers 1,2,3 and so on..

I shall try the row_number() method.


quote:
Originally posted by jezemine

What do you mean by serial number? do you mean just an increasing integer, like a row count number?

if so, check out the ROW_NUMBER() function, new in 2005: http://msdn2.microsoft.com/en-us/library/ms186734.aspx

see also RANK() and DENSE_RANK()


www.elsasoft.org

Go to Top of Page
   

- Advertisement -