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 |
|
pcc
Starting Member
2 Posts |
Posted - 2012-08-02 : 11:17:14
|
Hi this is my first post so I hope I am in the correct place.I have a table with 4 fieldsPart Spec Status SourceI need to identify all part/spec combinations where the status is ambiguous eg:Part Spec Status SourcePartA SpecX C A.txtPartA SpecX C B.txtPartA SpecX E C.txtPartB SpecY E D.txtPartB SpecY E E.txtIn this case, the data suggests that for PartA and SpecX, the status is both C and E, which cannot be the case.I need to run a query to identify where the same part/spec pairing has different statuses. The source of the file does not matter, although I need to display the source in the output. In this example, the required output will be:Part Spec Status SourcePartA SpecX C A.txtPartA SpecX C B.txtPartA SpecX E C.txtI'm sure this is fairly simple but I am fairly new to SQL and would appreciate guidance. Hope you can help.Regards Pete |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-02 : 11:32:02
|
| [code]SELECT t.*FROM Table tINNER JOIN(SELECT Part,SpecFROM tableGROUP BY Part,SpecHAVING COUNT(DISTINCT Status) >1)t1ON t1.Part = t.PartAND t1.Spec = t.Spec[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
pcc
Starting Member
2 Posts |
Posted - 2012-08-03 : 03:03:30
|
| Visakh16, thank you very much for your prompt reply. The code is exactly what I needed. RegardsPete |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-03 : 10:05:34
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|