Prorate a monthly charge to daily for a partial mo

2019-08-20 12:07发布

I'm using SQL Server and SSRS. I have a table with a monthly charge for a service. I need to be able to calculate what the charge is for a partial month. I need the monthly charge prorated to a daily charge, but I can't just divide by 30. I need it depending on what month I am looking at. 31 for months with 31 days, 28 for February, etc.

Can I do this in SQL?

1条回答
Rolldiameter
2楼-- · 2019-08-20 12:31

You can get the total number of days for current month by:

 SELECT DAY(EOMONTH(DateColumn))
 FROM TABLE

And in your case, I am guessing the query should look like:

 SELECT TotalCharges * 1.0/DAY(EOMONTH(DateColumn))
 FROM TABLE
查看更多
登录 后发表回答