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
 General SQL Server Forums
 New to SQL Server Programming
 Fetching a ordernumber for "upper" table in query

Author  Topic 

Liquid8
Starting Member

2 Posts

Posted - 2010-04-21 : 08:09:28
Hi all,

I'd need to fetch a ordernumber for project like this:

1 PROJECT firstProject PERSON X
1 PROJECT firstProject PERSON Y
1 PROJECT firstProject PERSON Z
2 PROJECT secondProject PERSON X
2 PROJECT secondProject PERSON Y
3 PROJECT thirdProject PERSON Y
3 PROJECT thirdProject PERSON Z

So the problem is that how could I get the ordernumber of the project so that number of persons in it dont increase that surrogate value which happens for example with ROW_NUMBER() ?

This is the query where I'd need to add it:
Select proj_name, person_name from PROJECT
INNER JOIN PERSON on PROJECT.PROJ_ID = PERSON.PROJ_ID

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-21 : 08:12:06
Table structure, sample data and wanted output in relation to sample data would be fine.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-21 : 09:01:39
Use dense_rank()

Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-21 : 23:36:38
on what basis you want numbering to be done?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Liquid8
Starting Member

2 Posts

Posted - 2010-04-22 : 02:44:16
Thank you, that DENSE_RANK() was just what I needed.
I wanted to rank the result according to project's name.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-22 : 04:50:47
ok then DENSE_RANK() OVER(PARTITION BY ProjectName) will do

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-22 : 06:27:58
quote:
Originally posted by visakh16

ok then DENSE_RANK() OVER(PARTITION BY ProjectName) will do

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




My guess is OP was already using it with PARTITION BY ProjectName with row_number()

Madhivanan

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

- Advertisement -