Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SPT Syntax help
Message
 
 
To
24/08/2010 17:11:51
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01478231
Message ID:
01478237
Views:
40
>Remote Database is DB2.
>
>I have table a which is a list of part numbers.
>
>Table b is a list of inspections performed on these part numbers. This table can have multiple records of each part number. Each record has a datetime stamp field and a status.
>
>I need a list of part numbers from table a where the last record(greatest datetime stamp) is status 2(rejected).
>
>
>
>Select partno From table a Where partno in (Select partno From table b Where status = 2 Order By datetime stamp Desc Fetch First 1 Rows Only)
>
>
>
>This gives me the first record of the part number group with a status of 2. However, there is a newer record with a status of 1 so this record should not be in result set.
select PartNo from Table a where a.Status = 2 and a.DateTime = (select max(DateTime) from Table b where a.PartNo = b.PartNo) 
Latest date for that PartNo.
If we don't have multiple statuses per PartNo, then
select PartNo from Table a where a.Status = 2 and a.DateTime = (select max(DateTime) from Table b)
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform