Home All Groups Group Topic Archive Search About

Assigning a row number to each row (for pagination and browse)

Author
28 Aug 2006 2:45 AM
Man-wai Chang
I have a table like this (uniqcode is the primary key):

uniqcode  name
--------  ----
1         bb
2         aa
3         aa
4         dd
5         cc

How could I create the following table out of the above one?

row_num   name   uniqcode
-------   ----   --------
1          aa      2
2          aa      3
3          bb      1
4          cc      5
5          dd      4

--
Man-wai Chang
Softmedia Technology Co., Ltd.
Tel: (852)3583 2780

Author
28 Aug 2006 1:47 AM
Steve Dassin
>In SQL Server 2000, you have to do more work:

More ng poopoo...just use RAC :)

Exec Rac
@transform='_dummy_',
@rows='uniqcode & [name]',
@rowsort='[name] & uniqcode',
@pvtcol='Report Mode',
@from='##T',
@defaults1='y',
-- Get your ranks by just typing a @rows column and give it a name.
-- Real difficult:) @rowindicators is one of several rank options.
@rowindicators='uniqcode{row_num}',
@select='select row_num,[name],uniqcode
               from rac
                 order by row_num'

row_num name uniqcode
-------     ----    --------
1               aa             2
2               aa             3
3               bb             1
4               cc              5
5               dd             4

Tested

Any ranking you can do in S2005 you can do with RAC in S2k.
But the reverse is not true.
As the say, "the 'SEQUEL' is usually not as good as the original" :)

Visit the original RAC @
www.rac4sql.net

best,
http://racster.blogspot.com/
Author
28 Aug 2006 8:41 AM
Man-wai Chang
Steve Dassin wrote:
>> In SQL Server 2000, you have to do more work:
>
> More ng poopoo...just use RAC :)
>
> Exec Rac
> best,
> http://racster.blogspot.com/

is Rac your special SP?


--
Man-wai Chang
Softmedia Technology Co., Ltd.
Tel: (852)3583 2780
Author
28 Aug 2006 7:29 PM
Steve Dassin
"Man-wai Chang" <i***@softmedia.hk> wrote in message
news:%23iKDV3nyGHA.4232@TK2MSFTNGP05.phx.gbl...
>
> is Rac your special SP?

More to the point, it could be 'your' special SP :)
Author
29 Aug 2006 2:09 AM
Mike C#
"Steve Dassin" <steve@nospamrac4sql.net> wrote in message
news:Os7$5htyGHA.3440@TK2MSFTNGP06.phx.gbl...
> "Man-wai Chang" <i***@softmedia.hk> wrote in message
> news:%23iKDV3nyGHA.4232@TK2MSFTNGP05.phx.gbl...
>>
>> is Rac your special SP?
>
> More to the point, it could be 'your' special SP :)

Why do I suddenly feel like I need a shower just from being in proximity to
this conversation?
Author
29 Aug 2006 12:55 AM
Steve Dassin
Hi Mike,

Do tell... Inquiring minds would like to know!

best,
steve

Show quote
"Mike C#" <x**@xyz.com> wrote in message
news:EqNIg.1420$h51.771@newsfe12.lga...
>
> "Steve Dassin" <steve@nospamrac4sql.net> wrote in message
> news:Os7$5htyGHA.3440@TK2MSFTNGP06.phx.gbl...
> > "Man-wai Chang" <i***@softmedia.hk> wrote in message
> > news:%23iKDV3nyGHA.4232@TK2MSFTNGP05.phx.gbl...
> >>
> >> is Rac your special SP?
> >
> > More to the point, it could be 'your' special SP :)
>
> Why do I suddenly feel like I need a shower just from being in proximity
to
> this conversation?
>
>
Author
31 Aug 2006 6:20 AM
Mike C#
When I read "it could be 'your' special SP" I thought I heard faint cheesy
70s porno music in the background.


Show quote
"Steve Dassin" <rac4sqlnospam@net> wrote in message
news:%23BW6%234xyGHA.1304@TK2MSFTNGP05.phx.gbl...
> Hi Mike,
>
> Do tell... Inquiring minds would like to know!
>
> best,
> steve
>
> "Mike C#" <x**@xyz.com> wrote in message
> news:EqNIg.1420$h51.771@newsfe12.lga...
>>
>> "Steve Dassin" <steve@nospamrac4sql.net> wrote in message
>> news:Os7$5htyGHA.3440@TK2MSFTNGP06.phx.gbl...
>> > "Man-wai Chang" <i***@softmedia.hk> wrote in message
>> > news:%23iKDV3nyGHA.4232@TK2MSFTNGP05.phx.gbl...
>> >>
>> >> is Rac your special SP?
>> >
>> > More to the point, it could be 'your' special SP :)
>>
>> Why do I suddenly feel like I need a shower just from being in proximity
> to
>> this conversation?
>>
>>
>
>
Author
29 Aug 2006 3:17 AM
Man-wai Chang
Steve Dassin wrote:
>> In SQL Server 2000, you have to do more work:
>
> More ng poopoo...just use RAC :)

Could you post the source of your RAC?

--
Man-wai Chang
Softmedia Technology Co., Ltd.
Tel: (852)3583 2780
Author
29 Aug 2006 12:52 AM
Steve Dassin
Hi,

RAC is a server utility.It's a system of sp's and a few functions
written entirely in t-sql.You can purchase RAC and if you like
you can also purchase the source code.We don't not make the source
code available otherwise.
We have many users of RAC amongst which is Mike C# who
is one of our biggest advocates.It's an extremely clean system :)

best,
steve
www.rac4sql.net

Show quote
"Man-wai Chang" <i***@softmedia.hk> wrote in message
news:%23$SxumxyGHA.1936@TK2MSFTNGP06.phx.gbl...
> Steve Dassin wrote:
> >> In SQL Server 2000, you have to do more work:
> >
> > More ng poopoo...just use RAC :)
>
> Could you post the source of your RAC?
>
> --
> Man-wai Chang
> Softmedia Technology Co., Ltd.
> Tel: (852)3583 2780
Author
29 Aug 2006 9:59 PM
Hugo Kornelis
On Mon, 28 Aug 2006 20:52:47 -0400, Steve Dassin wrote:

(snip)
>We have many users of RAC amongst which is Mike C# who
>is one of our biggest advocates.

Hi Steve,

I thought that Steve Dassin was the biggest RAC advocate? <g>

--
Hugo Kornelis, SQL Server MVP
Author
29 Aug 2006 11:44 PM
Steve Dassin
Hi,

Yeah, I think Mike drops RAC to a 'D FLAT' from a 'C#'  :(  :)

best (even to RAC haters:)
steve
P.S. If I was as good at programming as I am at marketing, would I be
answering a lot of posts?

Show quote
:)

"Hugo Kornelis" <h***@perFact.REMOVETHIS.info.INVALID> wrote in message
news:75e9f2l5366k7sr7e9q90cccqv3lqbichl@4ax.com...
> On Mon, 28 Aug 2006 20:52:47 -0400, Steve Dassin wrote:
>
> (snip)
>>We have many users of RAC amongst which is Mike C# who
>>is one of our biggest advocates.
>
> Hi Steve,
>
> I thought that Steve Dassin was the biggest RAC advocate? <g>
>
Author
31 Aug 2006 6:21 AM
Mike C#
I got nothing against RAC.  Don't even know what it is.  I was commenting on
your marketing tactics...

Show quote
"Steve Dassin" <steve@nospamrac4sql.net> wrote in message
news:e5zL%23U8yGHA.4232@TK2MSFTNGP04.phx.gbl...
> Hi,
>
> Yeah, I think Mike drops RAC to a 'D FLAT' from a 'C#'  :(  :)
>
> best (even to RAC haters:)
> steve
> P.S. If I was as good at programming as I am at marketing, would I be
> answering a lot of posts?
>
> :)
>
> "Hugo Kornelis" <h***@perFact.REMOVETHIS.info.INVALID> wrote in message
> news:75e9f2l5366k7sr7e9q90cccqv3lqbichl@4ax.com...
>> On Mon, 28 Aug 2006 20:52:47 -0400, Steve Dassin wrote:
>>
>> (snip)
>>>We have many users of RAC amongst which is Mike C# who
>>>is one of our biggest advocates.
>>
>> Hi Steve,
>>
>> I thought that Steve Dassin was the biggest RAC advocate? <g>
>>
>
>
Author
31 Aug 2006 6:06 AM
Steve Dassin
"Mike C#" <x**@xyz.com> wrote in message
news:DjvJg.77$pU7.23@newsfe10.lga...
> I got nothing against RAC.  Don't even know what it is.

That I should have to suffer the slings and arrows
of such blatant indiffernce is at times to great
a cross to bear. Would I only be but capabable of a
resolution. For I fear that the magnitude of the crime
against me is not as great as the sin I have committed.
Such are the vicissitudes of the art of persuasion
But perhaps from such humbleness comes an added
vigor.

best,
steve
Author
31 Aug 2006 10:26 PM
Mike C#
LOFL.  I'll take a look at RAC myself, right after I run whatever it is you
typed through Babelfish.

Show quote
"Steve Dassin" <rac4sqlnospam@net> wrote in message
news:e91S9vNzGHA.3280@TK2MSFTNGP02.phx.gbl...
> "Mike C#" <x**@xyz.com> wrote in message
> news:DjvJg.77$pU7.23@newsfe10.lga...
>> I got nothing against RAC.  Don't even know what it is.
>
> That I should have to suffer the slings and arrows
> of such blatant indiffernce is at times to great
> a cross to bear. Would I only be but capabable of a
> resolution. For I fear that the magnitude of the crime
> against me is not as great as the sin I have committed.
> Such are the vicissitudes of the art of persuasion
> But perhaps from such humbleness comes an added
> vigor.
>
> best,
> steve
>
>
Author
1 Sep 2006 1:41 AM
Steve Dassin
"Mike C#" <x**@xyz.com> wrote in message
news:OrJJg.976$X26.337@newsfe09.lga...
> LOFL.  I'll take a look at RAC myself, right after I run whatever it is
you
> typed through Babelfish.

Please take a bow for your splendid and most appropriate response.
For my part, allow me to exclaim a very big and proud - wow.

Henceforth we will forever be joined at the hip as a 'Bow-Wow'

best,
steve

Show quote
:)
Author
28 Aug 2006 3:46 AM
Steve Kass
Man-wai,

It's easiest in SQL Server 2005:

select
  row_number() over (order by name, uniqcode) as row_num,
  name,
  uniqcode
from T

In SQL Server 2000, you have to do more work:

select
  count(*) as row_num,
  T1.name,
  T1.uniqcode
from T as T1
join T as T2
on T2.name <= T1.name
and (
  T2.name < T1.name or
  T2.uniqcode <= T1.uniqcode
)

or more readably, but often less efficiently:


select
  count(*) as row_num,
  T1.name,
  T1.uniqcode
from T as T1
join T as T2
on T2.name < T1.name
or (
  T2.name <= T1.name and
  T2.uniqcode < T1.uniqcode
)

[not tested]

Steve Kass
Drew University
www.stevekass.com

Man-wai Chang wrote:

Show quote
>
> I have a table like this (uniqcode is the primary key):
>
> uniqcode  name
> --------  ----
> 1         bb
> 2         aa
> 3         aa
> 4         dd
> 5         cc
>
> How could I create the following table out of the above one?
>
> row_num   name   uniqcode
> -------   ----   --------
> 1          aa      2
> 2          aa      3
> 3          bb      1
> 4          cc      5
> 5          dd      4
>
Author
28 Aug 2006 8:40 AM
Man-wai Chang
> select
>  count(*) as row_num,
>  T1.name,
>  T1.uniqcode
> from T as T1
> join T as T2
> on T2.name <= T1.name
> and (
>  T2.name < T1.name or
>  T2.uniqcode <= T1.uniqcode
> )

Thanks

--
Man-wai Chang
Softmedia Technology Co., Ltd.
Tel: (852)3583 2780
Author
29 Aug 2006 1:10 AM
Man-wai Chang
> In SQL Server 2000, you have to do more work:
>
> select
>  count(*) as row_num,
>  T1.name,
>  T1.uniqcode
> from T as T1
> join T as T2
> on T2.name <= T1.name
> and (
>  T2.name < T1.name or
>  T2.uniqcode <= T1.uniqcode
> )

Where is the GROUP BY clause for the count(*)?

--
Man-wai Chang
Softmedia Technology Co., Ltd.
Tel: (852)3583 2780
Author
29 Aug 2006 10:01 PM
Hugo Kornelis
On Tue, 29 Aug 2006 09:10:03 +0800, Man-wai Chang wrote:

Show quote
>> In SQL Server 2000, you have to do more work:
>>
>> select
>>  count(*) as row_num,
>>  T1.name,
>>  T1.uniqcode
>> from T as T1
>> join T as T2
>> on T2.name <= T1.name
>> and (
>>  T2.name < T1.name or
>>  T2.uniqcode <= T1.uniqcode
>> )
>
>Where is the GROUP BY clause for the count(*)?

Hi Man-wai,

It's missing. Apparently, Steve either forgot to type it or left it out
when copying and pasting his code. You need to add this GROUP BY clause
to get it to work:

GROUP BY T1.name, T1.uniqcode

--
Hugo Kornelis, SQL Server MVP
Author
1 Sep 2006 12:00 AM
Kent Tegels
Hello Man-wai Chang,

Okay, aside from all the BS about RAC, did anybody ever answer the question?
:)

In SQL Server 2005, you can do this:

use scratch
go
set nocount on
create table t(uniqcode tinyint identity(1,1) primary key,name char(2))
go
insert into t(name) values ('bb')
insert into t(name) values ('aa')
insert into t(name) values ('aa')
insert into t(name) values ('dd')
insert into t(name) values ('cc')
go
select row_number() over (order by name) as row_num,name,uniqcode from t
go
drop table t

Thanks,
Kent Tegels, DevelopMentor
http://staff.develop.com/ktegels/
Author
1 Sep 2006 1:55 AM
Steve Dassin
"Kent Tegels" <kteg***@develop.com> wrote in message
news:b87ad741a3928c89b46d85684b0@news.microsoft.com...
> Hello Man-wai Chang,
>
> Okay, aside from all the BS about RAC, did anybody ever answer the
question?
> :)

The question pales in significance given your lack of recognition of
such exquisite expediency. Such surgical dissection is surely misplaced
and perhaps should be directed to those activities at less than arms length.
The thread has turned into a test of ones fortitude. I ask for strength
least I
may be required to part in such sweet sorrow.

best,
steve


Show quote
:)

AddThis Social Bookmark Button