Get Year wise data using SQL Server

Last Reply 8 months ago By dharmendr

Posted 8 months ago

Hello Dears 

I Have multiple table with an colum, createddate with date datatype 

i want to count data from table year wise 

as

  2017      2018      2019

  400         50          500

You are viewing reply posted by: dharmendr 8 months ago.
Posted 8 months ago

Hi ps222,

Refer below sample query to get Count Yearwise.

SELECT DATEPART(YEAR,OrderDate) [Year],COUNT(OrderDate) [Count] 
FROM Orders
GROUP BY DATEPART(YEAR,OrderDate)

Then display record as per your output use pivot query.

Pivot query with dynamic columns in SQL Server