Get Year wise data using SQL Server

Last Reply one year ago By dharmendr

Posted one year 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 one year ago.
Posted one year 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