I am using C#, trying to sort data by month. I have a date column as StartDate
and the query is as follows:
SELECT
CompanyKey, CompanyName, CAST(Month(StartDate) as varchar(2)) + '/' +
CAST(YEAR(StartDate) as varchar(4)) as StartDate, SUM(Visits)
FROM ProfileStats
WHERE StartDate between '2012/12/28' and '2015/12/29'
GROUP BY CompanyKey, CompanyName, StartDate, Visits
But if I use month (StartDate
) or CAST
syntax, it is throwing an exception:
Additional information: Object of type 'System.String' cannot be converted
to type 'System.DateTime'.
Any help/clue would be appreciated.