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 |
someebody
Starting Member
2 Posts |
Posted - 2011-03-08 : 21:15:08
|
Hello I need help with this query in sql server 2000, this is the table:IdOrder Status User1 Rcvd aa1 ProcOk aa1 Send aa2 Rcvd bb2 Fail bb3 Rcvd aa3 ProcOk aa3 Send aa4 Rcvd aa4 Fail aaAnd I need to show all the IdOrders where exists Status = 'Fail', it should be something like this:IdOrder Status User2 Rcvd bb2 Fail bb4 Rcvd aa4 Fail aaThanks in advance |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-03-08 : 21:18:59
|
[code]select *from yourtable twhere exists ( select * from yourtable x where x.IdOrder = x.IdOrder and x.Status = 'Fail' )[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
someebody
Starting Member
2 Posts |
Posted - 2011-03-08 : 21:44:15
|
Thank you so much! khtanSELECT IdOrder, StatusFROM TData AS xWHERE EXISTS (SELECT IdOrder, Status, [User] FROM TData AS y WHERE (x.IdOrder = IdOrder) AND (Status = 'Fail'))Done. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-03-08 : 21:49:09
|
you are welcome KH[spoiler]Time is always against us[/spoiler] |
|
|
|
|
|