all groups > sql server programming > june 2005 >
You're in the

sql server programming

group:

Sequence Table to generate ROWNUM


Sequence Table to generate ROWNUM jsfromynr
6/24/2005 11:39:40 PM
sql server programming:
Hi all,
I am looking for a way where we can use Sequence Table to generate row
number for non unique rows .
(Sequence is a table of numbers from 1 to (n); this is a common SQL
programming trick. )

With warm regards
Jatinder
Re: Sequence Table to generate ROWNUM jsfromynr
6/25/2005 3:31:11 AM
Thanks David,

In case of Authors Table it is easy to count number of rows having id
less than a particular row that is perfectly OK.
But what if the query is complex and I wish to number them .
One method would be again as suggested by you but using a view [
instead of query becuase the query is complex]

If the changes are very less for example in entire list of columns only
one coulmn is changing then we have to find a unique id like this
(columna+coumnb+columnc....)<=(columna+coumnb+columnc....)
I am not opposing this approach but looking for a simple approach

Or other method (if possible ) to use sequence table.

Roji. P. Thomas Suggested using IDENTITY which is again perfectly OK
select identity(int,1,1) myid,* into newTable from BaseTable
then
select * from NewTable

With warm regards
Jatinder
Re: Sequence Table to generate ROWNUM David Portas
6/25/2005 10:34:25 AM
What does "non unique rows" mean? Why would you want to store non unique
rows?

Perhaps you just mean you want to number results in a query. You don't need
a sequence table to do that. For example:

SELECT
(SELECT COUNT(*)
FROM Authors
WHERE au_id <= A.au_id) AS row_num,
*
FROM Authors AS A

Better still, do it client side.

--
David Portas
SQL Server MVP
--

Re: Sequence Table to generate ROWNUM David Portas
6/25/2005 11:37:07 AM
I think the simplest approach is client side. The example code you posted
adds the numbers in an arbitrary order. Your narrative also suggests you
aren't too concerned about the sequence ("we have to find a unique id"). In
other words your requirement has nothing to do with the data, it's
presumably just for presentation purposes. Presentation belongs in the
client / middle tier.

--
David Portas
SQL Server MVP
--

Re: Sequence Table to generate ROWNUM Roji. P. Thomas
6/25/2005 1:00:25 PM
Why dont you use the IDENTITY feature instead?


--
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com


[quoted text, click to view]

AddThis Social Bookmark Button