I wrote sp like below,
Alter procedure First_Proc
(@fromdate datetime,
@todate datetime
)
as
begin
select DATEPART(YY,ModifiedDate) as Year
,DATEPART(QQ,ModifiedDate) as Quarter
,DATEPART(MM,ModifiedDate) as Month
,Name
,rowguid
from [AdventureWorks2012].[Production].[ProductModel]
where ModifiedDate between (@fromdate) and (@todate)
group by DATEPART(YY,ModifiedDate),DATEPART(QQ,ModifiedDate),DATEPART(MM,ModifiedDate)
order by DATEPART(YY,ModifiedDate),DATEPART(QQ,ModifiedDate),DATEPART(MM,ModifiedDate)
end
But am getting following Error...
Column 'AdventureWorks2012.Production.ProductModel.rowguid' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Can anyone one help me?