Someone wrote the below code to run in SQL server 2005. For some strange reason after months of running fine it comes up with the error
"The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value"
The sql code is needed to run a crystal report, which comes up with the same error. I have looked at this for a couple of days with no results so any help would be appreciated.
SELECT TOP (100) PERCENT
CAST(cal.period AS int) AS period,
CAST(SUM(CONVERT(decimal(12, 2), CASE WHEN CONVERT(smalldatetime, invo.[grn posted],
103) <= CONVERT(smalldatetime, invo.[statdeldte], 103) THEN 1 ELSE 0 END)) / CAST(COUNT(*) AS int) * 100 AS decimal(12, 2)) AS Actual,
95 AS Target
FROM dbo.ZSPO AS invo INNER JOIN
dbo.Period_cal AS cal ON CONVERT(smalldatetime, invo.[GRN Posted], 103) = CONVERT(smalldatetime, cal.Date, 103)
WHERE (invo.Material <> '') AND (CAST(REPLACE(invo.[GRN Qty], ',', '') AS int) > 0)
GROUP BY cal.period
HAVING (cal.period >=
(SELECT period
FROM dbo.Period_cal
WHERE (Date = CONVERT(char(10), DATEADD(dd, - 61, GETDATE()), 103))))
"The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value"
The sql code is needed to run a crystal report, which comes up with the same error. I have looked at this for a couple of days with no results so any help would be appreciated.
SELECT TOP (100) PERCENT
CAST(cal.period AS int) AS period,
CAST(SUM(CONVERT(decimal(12, 2), CASE WHEN CONVERT(smalldatetime, invo.[grn posted],
103) <= CONVERT(smalldatetime, invo.[statdeldte], 103) THEN 1 ELSE 0 END)) / CAST(COUNT(*) AS int) * 100 AS decimal(12, 2)) AS Actual,
95 AS Target
FROM dbo.ZSPO AS invo INNER JOIN
dbo.Period_cal AS cal ON CONVERT(smalldatetime, invo.[GRN Posted], 103) = CONVERT(smalldatetime, cal.Date, 103)
WHERE (invo.Material <> '') AND (CAST(REPLACE(invo.[GRN Qty], ',', '') AS int) > 0)
GROUP BY cal.period
HAVING (cal.period >=
(SELECT period
FROM dbo.Period_cal
WHERE (Date = CONVERT(char(10), DATEADD(dd, - 61, GETDATE()), 103))))