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 |
|
vNz
Starting Member
1 Post |
Posted - 2008-02-22 : 04:37:27
|
| Hi everybody,I am trying to get this query working :SELECT DISTINCT ExPOIdFROM dbo.PurcHdr, dbo.PurcDetWHERE dbo.PurcHdr.InPurcId = dbo.PurcDet.ExPurcId AND PurcType = 2 AND NOT EXISTS ( SELECT DISTINCT ExPOId FROM dbo.PurcDet, dbo.PurcHdr WHERE dbo.PurcHdr.InPurcId = dbo.PurcDet.ExPurcId and (PurcType = 3) )But I get a blank result, even with ExPOId NOT IN... I actually want all the ExPoId of type 2 that doesn't appear in ExPoId of type 3.I checked my queries separately and I know that there must be values in the result.Can someone help me?The thing is that I can't use an EXCEPT command because I need to put that query in a view.Thanks,Vincent. |
|
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-02-22 : 05:30:29
|
| try:SELECT DISTINCT ExPOIdFROM dbo.PurcHdr inner join dbo.PurcDetON dbo.PurcHdr.InPurcId = dbo.PurcDet.ExPurcId where ExPOId NOT IN (SELECT DISTINCT ExPOId FROM dbo.PurcDet Inner JOIN dbo.PurcHdrON dbo.PurcHdr.InPurcId = dbo.PurcDet.ExPurcId where PurcType = 3) and PurcType = 2 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-22 : 06:19:29
|
or:-SELECT DISTINCT ph.ExPOIdFROM dbo.PurcHdr phJOIN dbo.PurcDet pdON ph.InPurcId = pd.ExPurcId AND ph.PurcType = 2LEFT JOIN (SELECT DISTINCT ExPOIdFROM dbo.PurcDet pdJOIN dbo.PurcHdr phON ph.InPurcId = pd.ExPurcId and (ph.PurcType = 3))tmpON tmp.ExPOId=ph.ExPOIdWHERE tmp.ExPOId IS NULL |
 |
|
|
|
|
|