--year SelectM as [Date],sum( Case when DatePart(Month, Createdatetime)=M Then 1 Else 0 End) as [Count] from [dbo]. Crmcustomer C, (Select 1mUnion All Select 2 Union All Select 3 Union All Select 4 Union All Select 5 Union All Select 6 Union All Select 7 Union All Select 8 Union All Select 9 Union All Select Ten Union All Select One Union All Select A) AAwhere '2018'= Year(Createdatetime)Group bym; --this month Select DATEPART( Day, Createdatetime) as [Date],COUNT(ID) as [Count] from [dbo]. CrmcustomerWHERE DATEPART(MM, Createdatetime)= DATEPART(MM,GETDATE()) and DATEPART(YY, Createdatetime)= DATEPART(YY,GETDATE()) Group by DATEPART( Day, Createdatetime)
--this week Select Convert(nvarchar(Ten), Createdatetime, -) as [Date],COUNT(ID) as [Count] from [dbo]. Crmcustomerwhere DateDiff(Week, Createdatetime,getdate())=0 Group by Convert(nvarchar(Ten), Createdatetime, -)
SQL Server displays charts based on time statistics