Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please advice what went wrong with

Status
Not open for further replies.

BenjaminLim

IS-IT--Management
May 24, 2000
73
GB
Please advice what went wrong with the following syntax. It could not extract data that is (lhldgr = 'GWMLDGR' and lhbook = 'GWMACT') though I did not exclude it in the syntax below. But when I tried to perform select query I was able to select records that has these criteria : i.e. lhyear = '1998' and lhperd in ('5','6') and lhldgr = 'GWMLDGR' and lhbook = 'GWMACT'

=============================
select *
from vgaglh
where lhyear = '1998' and lhperd in ('5','6') and
(lhldgr != 'GWMLDGR' and
lhbook not in ('GWM1997','GWMBUD','GWMALOVHD','GWMAOHPROD'));
=============================

Please advice. Thanks.
 
Please review your "where" clause. It certainly looks to me as if you are excluding the rows you expect to see (lhldgr != 'GWMLDGR').
 
I am trying to exclude only those that has (lhldgr != 'GWMLDGR' and lhbook not in ('GWM1997','GWMBUD','GWMALOVHD','GWMAOHPROD')) but I would like lhldgr = 'GWMLDGR' and lhbook = 'GWMACT' to be included. Does it sound reasonable?

Alternatively kindly suggest syntax where I can extract what I wanted.

Thanks.
 
I am unclear what you are actually trying to exclude. Your last post indicates that you want

select *
from vgaglh
where lhyear = '1998' and lhperd in ('5','6') and
not (lhldgr != 'GWMLDGR' and
lhbook not in ('GWM1997','GWMBUD','GWMALOVHD','GWMAOHPROD'));

However, I suspect it's more likely you really want to exclude rows with lhldgr = 'GWMLDGR' which also have lhbook in ('GWM1997','GWMBUD','GWMALOVHD','GWMAOHPROD'). If so, your query should be

select *
from vgaglh
where lhyear = '1998' and lhperd in ('5','6') and
not (lhldgr = 'GWMLDGR' and
lhbook in ('GWM1997','GWMBUD','GWMALOVHD','GWMAOHPROD'));

This, however would include all rows where lhldgr != 'GWMLDGR'. If you don't want these, you would write

select *
from vgaglh
where lhyear = '1998' and lhperd in ('5','6') and
lhldgr = 'GWMLDGR' and
lhbook not in ('GWM1997','GWMBUD','GWMALOVHD','GWMAOHPROD');
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top