Re-order reports sometimes give an error 'Failed to retrieve data from the database' when running

Problem

Weighted YTD Average Re-Order and Replenish Re-Order reports can sometime give an error 'Failed to retrieve data from the database' when running

Solution

Sound SQL skills are required

A good knowledge of SQL is required to complete this task.



The issue was caused by the underlying stored procs declaring a varchar variable too small to hold the SQLstatement.  We have modified "usp_Jiwa_PurchaseOrder_ReplenishToMinimum" and "usp_Jiwa_PurchaseOrder_WeightedYTDAverage" to use VARCHAR(MAX) to solve the issue.  

Download the attached stored procedures to run over the data.