Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to create report for month

I have created for one day...

Need to repair for mont

Some help

What I have tried:

select datum as Datum, SUM (Try_Convert(float,[iznos_sa_pdv])) as UKUPNO
from mp_kasa_lista
where [datum] >= CONVERT(datetime, convert(varchar(10), GETDATE() ,120), 120)
AND   datum <  DATEADD(day, 1, convert(datetime, convert(varchar(10), getdate(), 120), 120)) and tip_placanja='Virman'
group by datum
Posted
Updated 2-May-18 23:45pm

GROUP BY combines values which match exactly - so values which differ by even 1,000th of a second will all be in separate groups.

To group value for a month, you need to specify the month in both the SELECT and thge GROUP BY parts of the command.
You can do that by using DATEPART to subtract the day of the month from the DATETIME value to "normalize" them to the 1st of the month, then convert them to DATE to eliminate any time part.
Or use DATEPART to extract the month and year and use those instead.
 
Share this answer
 
You can do that by using MONTH (Returns an integer that represents the month of the specified date):
select datum as Datum, SUM (Try_Convert(float,[iznos_sa_pdv])) as UKUPNO
from mp_kasa_lista
where MONTH([datum]) = MONTH(GETDATE()) and tip_placanja='Virman'
group by datum
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900