SQLTeam.com | Weblogs | Forums

Monthly Sql Statement Run on any date gives sum of the month

sql2012

#1

Hi Expert !
I need help to make a query that reflect the monthly data when i running the query on any date of the month.


#2
  1. what does your data look like - do you have a date
  2. what have you tried
  3. do you mean the last 30 days or last month (month of December)

#3

Hi,
I tried below.
I need example when I run the query 3 date of the month it give me sum of the month , I mean any date which I put the query calculate the sum of the month value?

 SELECT   SUM(value) ,Name FROM table   
Where START_DATETIME >= CAST(CONVERT(VARCHAR, YEAR('31-OCT-2016')) + '-' + CONVERT(VARCHAR, MONTH('31-OCT-2016')) + '-' + CONVERT(VARCHAR, 1) AS DATETIME)
AND START_DATETIME < CAST(CONVERT(VARCHAR, YEAR('31-OCT-2016')) + '-' + CONVERT(VARCHAR, MONTH('31-OCT-2016')+1) + '-' + CONVERT(VARCHAR, 1) AS DATETIME)
GROUP BY Name