I am working with SQL R2 2008. I am trying to select date based on YEAR, Months in Year. I am trying to Group By YEAR in nvarchar.
My record in SQL has the Date format stored as like this (dd/mm/yyyy hh:mm)
10/11/2015 10:01
With the help of previous question in Stack - How to Group by Year I tried the following:
SELECT
T.[Date]
FROM (SELECT
CONVERT(varchar, CAST([U_DATE_TIME_VALUE] AS datetime), 3) AS [Date],
ROW_NUMBER() OVER (PARTITION BY YEAR(CAST([U_DATE_TIME_VALUE] AS datetime)) ORDER BY (SELECT
1)
) AS rn
FROM [FuelData]) AS T
WHERE T.rn = 1
ORDER BY T.[Date]
But I get the following Year.
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
- How can I overcome this issue.?
- What if I want to select Year and Month alone from the Record. (i.e. 11/2015 alone from the record).
Can some one pls help me. Thank you in advance.