Posted on 2008-10-16
I have a data set which I need to count the monthly entries. For example
To do this I have put together some code which like this;
SELECT CAST(MONTH([Rdate]) AS VarChar(20)) + '-' + CAST(YEAR([Rdate]) AS VarChar(20)) AS Month, COUNT([Rdate]) AS Rs
GROUP BY [Rdate]
ORDER BY RIGHT([Rdate], 4), CAST(LEFT([Rdate], CHARINDEX('-', [Rdate]) - 1) AS INT)
However I am getting a error message which looks like this;
Invalid lenght passed to SUBSTRING function.
I am not sure what is wrong?