473,382 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

SQL Statement - Join

Hi,

I'm having trouble creating a Crystal report. Usually when this happens I go back to Query Analyzer and try to get the results I want using SQL. I can't even get that this time. Hoping someone knows how to do this. :)

I have two tables, a WORK_ORDER table and LABOR_TICKET table. The goal is to find a released WORK_ORDER that hasn't had a labor ticket against it in the last 2 weeks. So no work orders will fall between the cracks.

WORK_ORDER table has these fields:
BASE_ID
LOT_ID
STATUS
TYPE

The BASE_ID and LOT_ID make up the primary key.

The LABOR_TICKET table has these fields:
ID
WORKORDER_BASE_ID
WORKORDER_LOT_ID
TRANSACTION_DATE

I want to find all of the WORK_ORDERS that haven't had a labor ticket against them in the last two weeks.

I tried something like this:

Select W.BASE_ID||' '||W.LOT_ID,LT.TRANSACTION_DATE
from WORK_ORDER W, LABOR_TICKET LT
where W.BASE_ID||W.LOT_ID =
LT.WORKORDER_BASE_ID||LT.WORKORDER_LOT_ID
and lt.TRANSACTION_DATE = (select TRANSACTION_DATE from LABOR_TICKET LT, WORK_ORDER W where
W.BASE_ID = LT.WORKORDER_BASE_ID);

but the sub-select is only grabbing one record - not the max trans date for each work order base + lot.

I'd love some help.

Thanks!
Jul 21 '06 #1
2 2047
You must use [b]in clause
Jul 21 '06 #2
Select W.BASE_ID||' '||W.LOT_ID,LT.TRANSACTION_DATE
from WORK_ORDER W, LABOR_TICKET LT
where W.BASE_ID||W.LOT_ID =
LT.WORKORDER_BASE_ID||LT.WORKORDER_LOT_ID
and lt.TRANSACTION_DATE in (
select TRANSACTION_DATE
from LABOR_TICKET LT, WORK_ORDER W
where W.BASE_ID = LT.WORKORDER_BASE_ID
and TRANSACTION_DATE = lt.TRANSACTION_DATE )
Jul 21 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: +Vice | last post by:
Can anyone help me translate this statement from using the legacy outer joins to the SQL-92 standards? Select CA.* From Customer C, Shipper S, Customer_Order CO, Cust_Address CA Where...
1
by: brett | last post by:
Here is my SQL string: "SELECT to_ordnum, to_orddate," _ & "(SELECT SUM((DDPROD.pr_stanmat * DDPROD.pr_prfact) * (DOBOM2.b2_quant * DDORD.or_quant)) FROM DDPROD INNER JOIN DOBOM2 ON...
2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
14
by: Ryan | last post by:
I want to do the following SQL statement in Access. However, it won't allow me to have the secondary part of my join statement and tells me that this is not supported. OK, so Access doesn't support...
10
by: SueB | last post by:
I currently have a 'mail-merge' process in my Access db project. It generates custom filled out Award Certificates based on an SQL SELECT statement in a VBA routine invoked by clicking on a...
14
by: Matt | last post by:
I need to add the following variable into an SQL statement and not sure how to do it. strGCID needs to be inserted into the following statement: SQL = "SELECT tblContacts.* FROM tblContacts...
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: ...
8
by: nano2k | last post by:
Hi Shortly, I keep invoices in a table. Occasionally, someone will fire the execution of a stored procedure (SP) that performs several UPDATEs against (potentially) all invoices OLDER than a...
8
by: gimme_this_gimme_that | last post by:
I want to execute the following SQL statement for a single emp.emp_id. Just adding and emp.emp_id=256 to the end of the statement results in a SQL statement that on average takes 5.5 seconds. ...
3
by: Eric Davidson | last post by:
DB2 9.5 I keep geting the message. SQL0101N The statement is too long or too complex. SQLSTATE=54001 When one of my sql statements takes over 60 seconds to compile the sql statement. Is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.