Hello I have this code I am trying to fix, the issue is that when I pass a parameter within the same year say
startDate = 01/01/2011 EndDate 07/01/2011
It works it returns the correct data but the issue is when I try to use it with a different year, say
startDate = 02/01/2011 EndDate 01/25/2012
--(wont work shows blank all thought there is data in both years).
Here is my sql code
ALTER PROCEDURE [dbo].[GetOrderByDateRange]
@startDate nvarchar(50),
@endDate nvarchar(50)
AS
BEGIN
DECLARE @days varchar(100)
set @days = DATEDIFF(d, @StartDate, DATEADD(day,+1,@EndDate))
SELECT distinct(CONVERT(char(10), OrdDate, 101)) as OrdDate,
COUNT(PurchaseId) as OrdCount,
SUM(Total) as OrdTotals,
AVG(Total) as AvgOrdAmount,
SUM(SubTotal) as Net,
@days as 'Days'
FROM [PurchaseOrders]
WHERE CONVERT(char(10), OrdDate, 101) >= @startDate
AND CONVERT(char(10), OrdDate, 101) <= @endDate
GROUP BY CONVERT(char(10), OrdDate, 101)
END
GO
Don’t use
CONVERT… assuming OrdDate is aDATETIMEcolumn, it should be: