Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Selection Criteria problem Post Reply Post New Topic
Author Message
Krazy Kasper
Newbie
Newbie
Avatar

Joined: 11 Jul 2007
Location: United States
Online Status: Offline
Posts: 23
Quote Krazy Kasper Replybullet Topic: Selection Criteria problem
    Posted: 30 Dec 2008 at 2:33pm

Using Crystal Reports 2003 and accessing several database tables (via ODBC) I need to select all of the material ids associated with invoices that contain a specific material id. There are about 15,000 invoices that will contain approximately 70,000 material ids. (There is no restriction on the number of material ids that can be associated with a given invoice.) The field names are: InvoiceNumber and MaterialId

 

In effect I’m trying to say “If InvoiceNumber contains MaterialId “51-103-000000”, then select all material ids associated with that invoice number.

 

Can anyone help me properly structure the Select Statement?

Thanks,

 

Krazy (Bill) Kasper

Krazy Kasper
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 31 Dec 2008 at 6:18am
select MaterialID, invoicenumber
from sometable st
join (select invoicenumber from sometable where materialID='xxx') ss on ss.invoicenumber = st.invoicenumber
 
this should return all invoices and their materialID for any invoice that contains the materialID in question.
 
Hope this helps.
IP IP Logged
Krazy Kasper
Newbie
Newbie
Avatar

Joined: 11 Jul 2007
Location: United States
Online Status: Offline
Posts: 23
Quote Krazy Kasper Replybullet Posted: 05 Jan 2009 at 4:48am
Thanks!!!
Krazy Kasper
IP IP Logged
Krazy Kasper
Newbie
Newbie
Avatar

Joined: 11 Jul 2007
Location: United States
Online Status: Offline
Posts: 23
Quote Krazy Kasper Replybullet Posted: 05 Jan 2009 at 2:27pm
I tried the solution you posted but am running into errors as Crystal Reports doesn't recognize "from" or "where".
My select statement follows:
Select {InvoiceDetail.MaterialId} and {InvoiceDetail.InvoiceId} from InvoiceDetail st where InvoiceDetail.MaterialId='51-103-000000') ss on ss.InvoiceId = st.InvoiceId
The table name is: InvoiceDetail
The field names are: MaterialId and InvoiceId
 
Appreciate any assistance you can provide.
Thanks,
 
Krazy Kasper
IP IP Logged
AntDC
Groupie
Groupie
Avatar

Joined: 23 Dec 2008
Online Status: Offline
Posts: 76
Quote AntDC Replybullet Posted: 05 Jan 2009 at 11:58pm
You seem to have got confused with the Aliasing of the table...
......from InvoiceDetail st

Here you have aliased InvoiceDetail as st and hence shoul;d always refer to it as st.  In the example sent, st was an alias for Some Table, so I'll use ID for invoice detail and MD fro MaterialDetail.

Something like the following (untested).......
Basically does the join between MD and ID but will only pull back rows where the invoice contains '51-103-000000'.  Remember the bottom select is sort of seperate and thus is not refered to as ID.

Hope this helps........


SELECTID.MaterialId, ID.InvoiceId FROM InvoiceDetail ID
INNER JOIN MaterialDetail MD ON
  MD.MaterialId = ID.MaterialId
WHERE
ID.InvoiceId in
(SELECT InvoiceId From InvoiceDetal WHERE MaterialId = 51-103-000000')
IP IP Logged
Krazy Kasper
Newbie
Newbie
Avatar

Joined: 11 Jul 2007
Location: United States
Online Status: Offline
Posts: 23
Quote Krazy Kasper Replybullet Posted: 06 Jan 2009 at 4:49am
Thanks. I'll work on it.
Krazy Kasper
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.014 seconds.