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.
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 OrStat001 Active001 Canceled001 Canceled002 Canceled002 Canceled003 ActiveWhat 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 @tabselect '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] |
 |
|
|
|
|