In the below code i have a function and a query the function will return batchrelease quantity.I have include the function in the select sqlquery it throws a error"Procedure or function dbo.GetBatchReleaseQuantity has too many arguments specified.".Please help me to overcome this issue.
SELECT p.ProductID,
p.ProductName,
ISNULL((SELECT ISNULL( CurrentStock,0.00)
FROM Productstatus PS
WHERE PS.ProductID =p.ProductID
AND PS.LocationID = 1
AND PS.StatusDateTime= '2014-08-27'
and PS.productid=p.productid),0) OpeningStockQuantity,
ISNULL((SELECT ISNULL( (CurrentStock*PS.UnitPrice),0.00)
FROM Productstatus PS
WHERE PS.ProductID =p.ProductID
AND PS.LocationID = 1
AND PS.StatusDateTime= '2014-08-27'
and PS.productid=p.productid),0) OpeningStockValue,
ISNULL((SELECT ISNULL( CurrentStock,0.00)
FROM Productstatus PS
WHERE PS.ProductID =p.ProductID
AND PS.LocationID = 1
AND PS.StatusDateTime= '2014-08-27'
and PS.productid=p.productid),0) ClosingStockQuantity,
ISNULL((SELECT ISNULL( (CurrentStock*PS.UnitPrice),0.00)
FROM Productstatus PS
WHERE PS.ProductID =p.ProductID
AND PS.LocationID = 1
AND PS.StatusDateTime= '2014-08-27'
and PS.productid=p.productid),0) ClosingStockValue,
(SELECT dbo.GetBatchReleaseQuantity(1,2, '2014-01-27 00:00:00', '2014-11-27 23:59:59') AS BatchReleaseQuantity
FROM Productstatus PS
WHERE
PS.LocationID = 1
and PS.productid=p.productid AND PS.StatusDateTime > = '2014-01-27 00:00:00' AND PS.StatusDateTime <= '2014-10-27 23:59:59' )
-- ISNULL((SELECT ISNULL( (dbo.GetBatchReleaseQuantity(1,2, '2014-01-27 00:00:00', '2014-11-27 23:59:59')),0.00)
--FROM Productstatus PS
--WHERE PS.ProductID =p.ProductID
-- AND PS.LocationID = 1
-- AND PS.StatusDateTime= '2014-08-27'
-- and PS.productid=p.productid),0) Batchout
FROM Product P
--- SELECT dbo.GetBatchReleaseQuantity(@i_LocationID,P.ProductID,@i_Date,@i_Date) From Product P
LEFT OUTER JOIN LocationProductMap LMP ON LMP.ProductID=P.ProductID
WHERE LMP.ProductInFlow=1
Function
ALTER FUNCTION [dbo].[GetBatchReleaseQuantity]
()
RETURNS int
--WITH ENCRYPTION
AS
BEGIN
DECLARE @i_LocationID VARCHAR(50)
DECLARE @i_ProductID INT
DECLARE @i_StartDate VARCHAR(50)
DECLARE @i_EndDate VARCHAR(50)
RETURN (SElECT SUM( BatchReleaseQuantity) AS BatchReleaseQuantity From BatchReleaseDetails BRD
LEFT OUTER JOIN BatchRelease BR ON BR.BatchReleaseID=BRD.BatchReleaseID
Where ProductId=@i_ProductID AND LocationID=@i_LocationID AND BRD.CreatedOn>=@i_StartDate AND BRD.CreatedOn<=@i_EndDate)