Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: SQL Command Problem - Help :-( Post Reply Post New Topic
Author Message
neilsja
Newbie
Newbie


Joined: 03 Oct 2011
Location: United Kingdom
Online Status: Offline
Posts: 12
Quote neilsja Replybullet Topic: SQL Command Problem - Help :-(
     Posted: 05 Oct 2011 at 1:28am
Hi All
 
I am very new to SQL and this is probably a very simple answer but I cannot fathom how to resolve the issue.
 
We pass an work order ref into a table, and this is held by the field 'SELDTL_STR_FLD3'.
 
I have an order start date and a priority, and all I want to do is return a 'due date' by taking the start date and adding the priority to that date:
 
select DATEADD(day,priority.PRIORITY_DAYS,wo.WORKORDER_START_DATE) as DueDate
from PM_PRIORITY as priority, PM_WORKORDERS as wo, GL_SELECTION_DTL as selection
where priority.PRIORITY_CODE = wo.PRIORITY_CODE
and wo.WORKORDER_REF = selection.SELDTL_STR_FLD3
 
So now when I run the report (for 2 orders for example), I get the following problem:

WO1 – Due Date = 01/10/11

WO1 – Due Date = 01/11/11
WO2 – Due Date = 01/10/11
WO2 – Due Date = 01/11/11
 
What I actually need is:

WO1 – Due Date = 01/10/11

WO2 – Due Date = 01/11/11

Now I know it is the SQL causing the problem, as it is just running this SQL statement against each record (twice for record 1, and twice for record 2), but I am not sure how to resolve it so I only get the 2 records I need.

Look forward to your reply.

James.

 
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 05 Oct 2011 at 5:06am

the fact that youa re getting 2 rows with different due dates leads me to belive you have either

2 rows per workorder_ref in wo with different start dates
or
2 rows per workorder_ref in priority with different priority dates
 
if this is the case you hav to decide which ones is the 'correct' one and then decide how to alwasy grab that value (likely a grouping with max or min)
IP IP Logged
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