Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

how to calculate sum for week,day ,month? In SQL SERVER

how to calculate sum for week,day ,month?

In SQL SERVER

4 Replies
jagan
Luminary Alumni
Luminary Alumni

Hi Yogesh,

Try like this

For Week:

SELECT

DATEPART (wk, DateFieldName) AS Week,

Sum(Sales) AS Sales

FROM TableName

Group By DATEPART (wk, DateFieldName);


For Month:

SELECT

DATEPART (m, DateFieldName) AS Month,

Sum(Sales) AS Sales

FROM TableName

Group By DATEPART (m, DateFieldName);


For Day:

SELECT

DATEPART (d, DateFieldName) AS Day,

Sum(Sales) AS Sales

FROM TableName

Group By DATEPART (d, DateFieldName);


Regards,

Jagan.



jagan
Luminary Alumni
Luminary Alumni

Hi Yogesh,

Check this link it has various date formats

DATEPART (Transact-SQL)

Regards,

Jagan.

Not applicable
Author

hi jagan,

thanks...

please give anuy example you have?

jagan
Luminary Alumni
Luminary Alumni

Hi,

Check this in your database tables, if you want to practice download Northwind or Pubs or Adventureworks database and practice.

Please close this thread by giving correct and helpful answers to the useful posts.

Regards,

Jagan.