Gillian_Pappas2002 (12/12/2013)
Thank you Sean.Sorry about the mess.
Hi. Thank you again for your response. That works very well to get rid of either status C or O, but what they want me to do is to look at all of the same customer order numbers and their status. If the same customer order number has ANY status of 'O', they do not want to see any of those customer order records. They only want to see like customer orders that All have a 'C' status.
Below is the before status before applying your solution. They do not want to see ANY Orders 905055 because it has one with a status of 'O'. but they would want to see order AW00000253 because it doesn't have any status's of 'O". I hope this makes sense and I appreciate all of your help.
Order# Line# STATUS
905055 1 C
905055 2 C
905055 3 C
905055 4 O
AW00000253 1 C
AW00000253 2 C
You really need to actually read the article that has been suggested. If you had read it you would see that just sticking some values in a post is nothing like consumable data. We want and need to see ddl (create table) and data (insert statements). What you should have posted would look like this.
create table #Something
(
OrderNum varchar(20),
LineNum int,
Status char(1)
)
insert #Something
select '905055', 1, 'C' union all
select '905055', 2, 'C' union all
select '905055', 3, 'C' union all
select '905055', 4, 'O' union all
select 'AW00000253', 1, 'C' union all
select 'AW00000253', 2, 'C';
Then we would be able to see and work with the same thing. This makes it really easy for us to help you.
Somebody like myself can then come along and post a query that meets your requirements. Something like this one...
select *
from #Something
where OrderNum in
(
select OrderNum
from #Something
group by OrderNum
having MAX(Status) = 'C'
)
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/