Prorate a monthly charge to daily for a partial month

。_饼干妹妹 提交于 2019-12-14 03:08:14

问题


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:


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


来源:https://stackoverflow.com/questions/48430690/prorate-a-monthly-charge-to-daily-for-a-partial-month

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!