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
 Other SQL Server Topics (2005)
 SQL Statement

Author  Topic 

clintv
Starting Member

1 Post

Posted - 2009-04-01 : 00:05:54
Hi, I'm very new to this can someone help me please :). I have a table with three columns namely ORNo, ORStat, ControlDate. The table have the following records:

OrNo OrStat
001 Active
001 Canceled
001 Canceled
002 Canceled
002 Canceled
003 Active

What i want is to retrieve the record that meets the ff criteria:
1. If an ORNo has an Active and Canceled ORStat, just retrieve the ORNo with 'Active' ORStat.
2. If an ORNo's ORStat is all Cancelled, select one record from the two with the most recent ControlDate.


Thanks for your help.

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-04-01 : 03:55:08
[code]
declare @tab table (OrNo varchar(3), OrStat varchar(10))

insert into @tab
select '001', 'Active'
union select '001', 'Canceled'
union select '001', 'Canceled'
union select '002', 'Canceled'
union select '002', 'Canceled'
union select '003', 'Active'

select OrNo, Min(OrStat) from @Tab group by OrNo
[/code]
Go to Top of Page
   

- Advertisement -