Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Dead Stock Report Post Reply Post New Topic
Author Message
stewpyd
Newbie
Newbie


Joined: 26 May 2008
Location: Australia
Online Status: Offline
Posts: 3
Quote stewpyd Replybullet Topic: Dead Stock Report
     Posted: 17 Jun 2008 at 6:09pm
I posted this under technical questions, but I think it should be in report design:
 
------------------------
 
I am fairly new to crystal reports and need help with the following problem. I am writing a dead stock write off report. The parameters and SQL are below.
 
I am having trouble with the section regarding stock not sold in the last 12 months. Does anyone have any tips on how I would do this part in crystal? I can use the second half of this statement : DATEDIFF(MONTH, apply_date, GETDATE()) <= 12   to get a true/false value for each apply date (each transaction date).
 
Now I need to find the MAXIMUM apply_date for each product to apply this filter, and only select those that return a true value (i.e. those products that have the most recent transaction date within the last 12 months).
 
Any ideas how to return the max transaction date for each product based on the part no and apply date?
 
Thanks
 
------------------------
 
 
-- Dead Stock Write Off Report --

-- --

-- Positive Quantity In Stock --

-- Not Sold in the last 12 Months --

-- Excludes Voided & NQB Items --

-- Includes Obsolete Items --

-------------------------------------

SELECT c.[description] AS 'Group'

, i.[description] AS 'Description'

, i.part_no AS 'Part No'

, dbo.PBS_fnQuantityInStock(il.part_no, il.location) AS 'In Stock'

, il.avg_cost AS 'Average Cost'

, dbo.PBS_fnQuantityInStock(il.part_no, il.location) * il.avg_cost AS 'Total Cost'

FROM inv_master i

INNER JOIN inv_list il ON il.part_no = i.part_no

LEFT JOIN category c ON c.kys = i.category

WHERE i.void <> 'V'

AND i.status <> 'V' -- NQB

AND dbo.PBS_fnQuantityInStock(il.part_no, il.location) > 0

AND (SELECT COUNT(*) FROM inv_tran WHERE part_no = i.part_no AND tran_type = 'S' AND DATEDIFF(MONTH, apply_date, GETDATE()) <= 12) = 0

ORDER BY c.[description], i.[description]

IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 17 Jun 2008 at 10:48pm
It's a bit tricky, but there is a suggestion for getting the max value from a group of related records at this post. As long as you are good with SQL (and you obviously are), then you should be okay making this example work for your report.

http://crystalreportsbook.com/Forum/forum_posts.asp?TID=1982&KW=max
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
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