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)
 SQL Logic

Author  Topic 

Bernard_za
Starting Member

6 Posts

Posted - 2003-07-16 : 05:51:07
I have a table with the following fields and data

PolicyID | RIID
---------------
123456789| 1-NPV
100055555| 1-WOP
123456789| 1-XOM
123586784| 1-ROP
123456789| 1-VPN

The table has many rows and I am looking for a easy way to find out which PolicyID has more than one RIID allocated to it. If the PolicyID only has one RIID it should not show.

Please help!

mr_mist
Grunnio

1870 Posts

Posted - 2003-07-16 : 06:05:51
SELECT
policyID, count(riid)
FROM
yourtable
group by policyid
having count (riid) > 1

-------
Moo. :)
Go to Top of Page

Bernard_za
Starting Member

6 Posts

Posted - 2003-07-16 : 06:15:19
This provides a list of PolicyID's with more than one RIID but I need it to show only if the RIID is different to the other RIID for the same PolicyID

Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2003-07-16 : 06:34:50
SELECT
policyID, count( distinct riid)
FROM
yourtable
group by policyid
having count ( distinct riid) > 1

-------
Moo. :)
Go to Top of Page
   

- Advertisement -