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 2005 Forums
 Transact-SQL (2005)
 Selecting Rows

Author  Topic 

madscientist
Starting Member

30 Posts

Posted - 2008-02-21 : 17:12:15
Hello again,

I have a question I hope someone can help me with. I have rows in a table with fields:

Policy_Number Transaction_Code Coverage_State Record_Type

14191ADCWC00100151 02 09 04
14191ADCWC00100151 02 31 04

I want to select both rows but the constraint is that the coverage_state has to equal "31". The reason both are included is that both coverage_states are under the same policy where at least one of the coverage_states is "31". I hope this makes sense and thank you for the help.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-02-21 : 17:39:45
[code]
select t2.*
from (select Policy_Number from YourTable where Coverage_State = 31) t1
join YourTable t2 on t1.Policy_Number = t2.Policy_Number
[/code]


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page
   

- Advertisement -