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 2000 Forums
 Transact-SQL (2000)
 RANK

Author  Topic 

Suhanti
Starting Member

9 Posts

Posted - 2009-02-26 : 10:41:20

Hello All,
I cannot access the database and I am writing the sql for a customer.
can you advise,
does SQLSERVER 2000, support

the rank function? for instance the following?

Select Account_num
,Account_open_dt
,Ins_txf_Batchid
,Product_id
,RANK( ) Over (partition by Ins_txf_Batchid ORDER BY Ins_txf_Batchid, account_open_dt)
from V0300_AGREEMENT
where account_num in ('11564090014')

Kind regards
Su

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-26 : 10:56:36
Equivalent in SQL 2000:

Select   t.Account_num
,t.Account_open_dt
,t.Ins_txf_Batchid
,t.Product_id
,(Select Count(*) from V0300_AGREEMENT Where Account_num = t.Account_num and
(Ins_txf_Batchid > t.Ins_txf_Batchid or
(Ins_txf_Batchid = t.Ins_txf_Batchid and
Product_id >= t.Product_id))) as Rank

from V0300_AGREEMENT t
where t.account_num in ('11564090014')
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-26 : 11:02:18
Why use Ins_txf_Batchid in the ORDER BY part? It is already used in the PARTITION BY part.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-26 : 11:04:07
[code]SELECT a.Account_num,
a.Account_open_dt,
a.Ins_txf_Batchid,
a.Product_id,
(SELECT COUNT(*) FROM V0300_AGREEMENT AS b WHERE b.Ins_txf_Batchid = a.Ins_txf_Batchid AND b.account_open_dt <= a.account_open_dt)
FROM V0300_AGREEMENT AS a
WHERE a.account_num = '11564090014'[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Suhanti
Starting Member

9 Posts

Posted - 2009-03-01 : 23:17:44
Hello All,
Thank you!! The first solution worked really well. I am really thankful for your help. I was really struggling to find a solution, as importing the data into ACCESS and appending a rank was an IMPOSSIBLE TASK!!

So honestly, I am so grateful. God Bless.
Su
Go to Top of Page
   

- Advertisement -