How to exclude row with date

I need to exclude data rows that have same auth_no when the discharge date is not null in any row.
So in the example below, all the rows with auth_no = 200 should be excluded because the last row has a discharge date.  The report should only display the first row of data where auth_no = 100.   Any sql help would be appreciated.

Service Date      auth_no      Discharge
1/5/2011      100      NULL
1/14/2011      200      NULL    --should be exluded
1/18/2011      200      NULL    --should be excluded
1/20/2011      200      NULL    --should be excluded
2/4/2011      200      1/22/2011  -- all auth_no = 200 should be excluded as discharge date is not null in this row.
lcalabroAsked:
Who is Participating?
 
Ephraim WangoyaCommented:
try
;with CTE
as
( select auth_no, max(Discharge) Discharge, COUNT(auth_no) DUP
  from table1
  group by auth_no
 )
 
 select * 
 from table1 A
 where exists ( select 1 
                from CTE
                where auth_no = A.auth_no
                and DUP =1
                and Discharge is null)

Open in new window

0
 
Alpesh PatelAssistant ConsultantCommented:
Select * From Table where  auth_no <> 200
0
 
lcalabroAuthor Commented:
thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.