Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Compare against next record value Post Reply Post New Topic
Author Message
Cassal Services
Newbie
Newbie
Avatar

Joined: 15 Aug 2011
Location: United States
Online Status: Offline
Posts: 2
Quote Cassal Services Replybullet Topic: Compare against next record value
     Posted: 26 Sep 2011 at 7:51am
I have two tables that need to be left outer joined.  First table holds all the purchase order information and the second table holds all the sales information.  They do not intersect at all.  Purchase_Order_Table is when we buy the product and Sold_Item_Table is when we sell products.  I do not control the database so I can not set up a stored procedure or design the table layouts to accommodate this need.  My question is how dou you test against the next record in a SQL statement??
 
To create a perpetual inventory I need to pull in the sales that occur between two purchase orders.  So I want to join the sales record to the purchase order until a new purchase order occurs.
 
 
 
Select ....
From Purchase_Order_Table
 
Left Join Sold_Item_Table on Sold_Item_Table.Date  > Purchase_Order_Table.PO_Date and Sold_Item_Table.Date < NEXT RECORD'S  Purchase_Order_Table.PO_Date
IP IP Logged
Luis2101
Newbie
Newbie


Joined: 14 May 2008
Online Status: Offline
Posts: 18
Quote Luis2101 Replybullet Posted: 28 Sep 2011 at 2:48am
It sounds like you need a subquery in your SQL statement.

Something like:
Select ....
From Purchase_Order_Table
Left Join Sold_Item_Table on Sold_Item_Table.Date  > Purchase_Order_Table.PO_Date and Sold_Item_Table.Date < (SELECT POTable2.PO_DATE FROM Purchase_Order_Table AS POTable2 WHERE [SOME CONDITION THAT UNIQUELY IDENTIFIES THE NEXT RECORD])

See this link for more:
http://msdn.microsoft.com/en-us/library/aa213252%28v=sql.80%29.aspx

Alternatively, you can store your records in a temp-table, and then use a cursor to iterate through one at a time, then apply whatever logic you need in a more straight-forward manner (like creating SELECT statements for each iteration to fetch whatever you need), it's more tedious, but may be easier to grasp if you're relatively new to SQL.
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