Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
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: 26 May 2008 at 2:15am
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?
 
Thanks
 
----------------------

USE TRAD013

GO

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

-- 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
hobiedave
Newbie
Newbie
Avatar

Joined: 22 May 2008
Location: United States
Online Status: Offline
Posts: 2
Quote hobiedave Replybullet Posted: 26 May 2008 at 4:49am
Originally posted by stewpyd

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


I don't really understand your database schema but it looks like you are referencing the inv_master table from your subquery.  I would try to rewrite it like this, but you may need to change the logic to meet your exact needs:

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

IP IP Logged
stewpyd
Newbie
Newbie


Joined: 26 May 2008
Location: Australia
Online Status: Offline
Posts: 3
Quote stewpyd Replybullet Posted: 17 Jun 2008 at 2:27am
OK,
 
So 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?
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