I figured it out !
Here it is:
select i.id, e.code
from dbo.hExceptionitem ei, dbo.hItem i, dbo.hException e
where ei.batchnumber = i.batchnumber
and ei.processingdate = i.processingdate
and ei.itemrow = i.rownumber
and ei.processingdate = e.processingdate
and...
Although i know there's a problem with this query:
select i.id
, e.code
from dbo.hExceptionitem ei
,dbo.hItem i
, dbo.hException e
Where ei.batchnumber = i.batchnumber
and ei.processingdate = i.processingdate
and ei.itemrow = i.rownumber
and...
Your wording "then you have limited your output to only records with that exception code" is exactly right. e.code IN ('18','1018','7018') DOES limit OUTPUT to only those records that have an '18','1018', or '7018' in the e.code field. The problem is that some of the records that are included in...
Sorry to take so long getting back, I have had a busy day so far ! Marc, the recordsets from both of your queries were identical. They include:
1st Record:
i.id:1DDA610116088299.0000000000004105489154 i.amt:299.00
i.batchnumber:8826
i.processingdate:11/01/2006
i.rownumber:2612...
OK.. note to self mostly, but here's what i'm going to try on Monday...
select i.id
, e.code
from dbo.hExceptionitem ei
,dbo.hItem i
, dbo.hException e
Where ei.batchnumber = i.batchnumber
and ei.processingdate = i.processingdate
and ei.itemrow = i.rownumber...
Wow, I don't know... i wrote up this query (which is an extension on Marc's idea), and thought for sure it would do the trick. It returned no records, but i the logic makes so much sense to me !!! this is driving me crazy.
select i.id
, e.code
from dbo.hExceptionitem ei
,dbo.hItem i
...
The reason i care about other exception codes is:
I'll be using a separate, simpler query to grab a bunch of items, including those that have codes '18', '1018', or '7018' as well as any other codes.
The query we're working on here has to select only those items that have only an exception...
Oh, man, i could scream ! I really thought you had nailed it when i first looked at the result set. Unfortunately, your statement is giving the same results as this one:
select i.amt, e.code
from (dbo.hExceptionitem ei join dbo.hItem i on (ei.batchnumber = i.batchnumber) and...
Hmm. I'm not dismissing what you're saying, but i also don't see the conflict... let's look strictly at the last couple parts of the where clause for a minute:
(e.code in ('18','1018','7018'))
AND ( E.CODE NOT BETWEEN '1' AND '17'
AND E.CODE NOT BETWEEN '19' AND '75')
AND ( E.CODE...
?? Did you want me to remove the entire where clause ? I'm not able to do that because of the size of the database (i risk crashing a production application with queries that are too demanding). i think you were asking just to eliminate some of the requirements...
so, i used the following...
Thanks Marc,
I'm at home right now, and I won't have a chance to test this until tomorrow when i'm at work again tomorrow. i'll check it out then, and i'll post back asap.
Jake
dbo is the database owner's name. The database i am working with here is DB2 UDB (7.2 to be exact). The between operand does work with strings... i tested it in a separate query that only used those expressions as criteria, and it did return the records i expected.
Hmmm.. this is interesting. I tried using "e.code='1018'", and got no records at all. In fact, the DB2 UDB prompt i'm running the query from flies through all iterations of the query (i'm running a loop to retrieve variable values in the date and i.num fields) in under a second.
When i use...
I am trying to write a query that will select records from a primary table when they meet two criteria conditions in that table and their associated records in the foreign key table match ONLY to one of the three values. The foreign key table can contain up to three records matching back to the...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.