Hi guys,
I am new to SQL.
I know there are plenty of YTD/MTD sql calculations but I have been unable to pass them any of them as parameters to may Stored Procedure.
If someone can help me solve at least two of them (let's say YTD/MTD). I will do the same for the rest of parameters (QTD/WTD) following the example. Please find my current SP below.
ALTER Procedure [dbo].[DIFOT_WH] AS Select CORDDocs.DateOpn AS 'CORD_DateOpen', CORDDocs.DocumentCode as 'CORD_DocumentCode', CDSPDocs.DocumentCode AS 'DESP_DocumentCode', Count(CORDLines.LneType) AS 'Cord_Lines', SUM(CORDLines.Qnty) AS 'CORD_Qty', CDSPLines.Status, Count(CDSPLines.Qnty) AS 'DESP_Lines', Sum(CDSPLines.Qnty) AS 'DESP_Qty', CORDDocs.DateReq AS 'CORD_DateReq', CDSPDocs.PostDate AS 'DESP_PostedDate', CASE When SUM(CORDLines.Qnty) = Sum(CDSPLines.Qnty) THEN 'IF' ELSE 'NOT IF' END as 'IFOT' From dbo.Documents AS CORDDocs INNER JOIN dbo.DocumentsLines AS CORDLines ON CORDDocs.DocID = CORDLines.DocID AND CORDLines.TrnType = 'L' AND CORDLines.LneType <> 'Fght' LEFT OUTER JOIN dbo.DocumentsLines AS CDSPLines ON CORDLines.TranID = CDSPLines.SourceID AND CDSPLines.TrnType = 'L' AND (CDSPLines.Status = 'Posted' OR CDSPLines.Status = 'Closed') LEFT OUTER JOIN dbo.Documents AS CDSPDocs ON CDSPLines.DocID = CDSPDocs.DocID WHERE (CORDDocs.DocumentName = 'DocCord') Group by CORDDocs.DateOpn, CORDDocs.DocumentCode, CDSPDocs.DocumentCode, CORDDocs.DateReq, CDSPDocs.PostDate, CDSPLines.Status ORDER BY CORDDocs.DateOpn,'CORD_DocumentCode'
I appreciate all your help
Thanks
Eric