如何使用T-SQL计算金额 [英] How can calculate amount using T-SQL
本文介绍了如何使用T-SQL计算金额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何计算金额:
金额=(当前日期 - 结束日期)* 2
如何在SQL中编写代码来实现相同的目标。
How can calculate amount such that:
amount = (current date - end date) * 2
How to write code in SQL to achieve the same.
推荐答案
尝试
Try
SELECT DATEDIFF(d, GETDATE(), endDate) * 2 AS [Days times 2] FROM MyTable
以下代码将执行此操作:
Following code will do that:
DATEDIFF(day,endDate,currentDate) * 2
如果需要,你可以写一个if混淆来检查上面代码的输出是否是正整数。
更多:http://msdn.microsoft.com/en-IN/library/ms189794.aspx [ ^ ]
谢谢。
If needed you can write an "if" confition to check whether output of above code is positive integer or not.
For more: http://msdn.microsoft.com/en-IN/library/ms189794.aspx[^]
Thanks.
这篇关于如何使用T-SQL计算金额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文