Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
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
Partner - Champion III
Partner - Champion III

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
Partner - Champion III
Partner - Champion III

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
Partner - Champion III
Partner - Champion III

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.