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.
Author |
Topic |
artbishop
Starting Member
18 Posts |
Posted - 2009-02-19 : 00:38:20
|
How do i get the following result:RANKID NAMEID NAME0 1 Alfred1 2 Jen2 5 Amber2 3 Maricel1 4 Philipif I have two SQL database table:first table is dbo.NAMEID NAME1 Alfred2 Jen3 Maricel4 Philip5 Amberthen second table is RANKNAMEID RANKID1 02 13 24 15 2thankshere's the formula...SELECT dbo.T_Relationships.PARENT_NAMEID, dbo.T_Relationships.NAMEID, dbo.T_Names.NAMEFROM (SELECT ROW_NUMBER() OVER (partition BY dbo.T_Relationships.PARENT_NAMEIDORDER BY NAME) AS seq, dbo.T_Relationships.PARENT_NAMEID, dbo.T_Relationships.NAMEID, dbo.T_Names.NAMEFROM dbo.T_Names INNER JOINdbo.T_Relationships ON dbo.T_Names.ID = dbo.T_Relationships.NAMEID) ZORDER BY seq |
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-02-19 : 00:54:46
|
dont post duplicates ,try thisdeclare @Name Table ( ID int, NAME varchar(32))insert into @name select 1, 'Alfred' union allselect 2 ,'Jen' union allselect 3 ,'Maricel' union allselect 4 ,'Philip' union allselect 5 ,'Amber'declare @rank table (NAMEID int, RANKID int)insert into @rankselect 1, 0 union allselect 2, 1 union allselect 3, 2 union allselect 4, 1 union allselect 5, 2declare @cnt Intselect @cnt = count(*) from @nameselect r.rankid,n.id,n.namefrom @name ninner join @rank r on r.nameid = n.id order by case when id = (select max(id) from @name) then id-((@cnt/2)+1) else id end |
|
|
artbishop
Starting Member
18 Posts |
Posted - 2009-02-19 : 01:07:44
|
oppps sorry about that...thanks Nageswar9 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-02-19 : 01:26:36
|
quote: Originally posted by artbishop oppps sorry about that...thanks Nageswar9
ok, Welcome |
|
|
|
|
|
|
|