Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL - How Do I Do This?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00681371
Message ID:
00681445
Views:
17
The first select will pull all active records. The second select will pull all inactive records with MAX RevNum value.
SELECT * ;
  FROM lineitem  ;
  WHERE RecType = "A" ;
UNION ALL ;	
SELECT * ;
  FROM lineitem t1 ;
  WHERE RevNum IN ( SELECT MAX(RevNum) ;
			FROM lineitem t2 ;
			WHERE RecType = "I" ;
				AND t2.ParentId = t1.ParentId ;
				AND t2.LineId = t1.LineId ) ;
ORDER BY 2, 3, 4 ;
INTO CURSOR crsResult
>I have a header/lineitem problem.
>
>The header table has the following fields:
>RecordId   DocId    RevNum
>------------------------------------
>       1    0001         3
>
>
>The LineItems has:
>
>RecordId   ParentId   LineId    RevNum   OrigRev  RecType
>------------------------------------------------------------
>    1          0001      123         1       999        I
>    2          0001      123         2       999        I
>    3          0001      123         3       999        A
>    4          0001      890         1       999        I
>    5          0001      890         2       999        A
>
>
>
>I need to pull all active record (RecType = "A") and the record
>which was active just prior to the currently active record.
>
>So in the example above, if I wanted to see the active line item
>and previous record for line item 123, I would get the line items
>record Id's with 3 and 2.
>
>Any ideas?
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform