会计和数据库设计,存储借方和贷方金额 [英] Accounting and Database design, storing debit and credit amount

查看:137
本文介绍了会计和数据库设计,存储借方和贷方金额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:在以下情况下,我应该将我的所有金额存储为正的十进制金额,然后将金额标记为借方还是贷方,而不是将借方存储为负数,而将贷项存储为正数?

QUESTION: In the case below should I have stored all my amount as positives decimal amounts then flag the amount as either being a "Debit" or "Credit" rather than storing debits as negative amount and credits as positive amount?

在我的数据库设计中,我将借方存储为负数,将贷方存储为正数。

In my database design, I store "debit" as negative amount, and credit as positive amount.

现在有时报告结果有时会出错,因为如果这样做

Now in reporting sometimes the results come out wrong because if you do this

TotalAmount = Amount-Fee,并且提款金额为$ 100 ,费用为$ 1。

TotalAmount = Amount-Fee, and if withdraw amount is $100, and fee is $1.

您最终会得到-$ 100- $ 1 =-$ 101,这是不正确的结果!

You would end up with -$100-$1 = -$101, which is the incorrect result!.

推荐答案

您可以在sql server中使用ABS函数来获取绝对值。

You can use the ABS function within sql server to get the absolute value. This would allow you to treat negative numbers as positive ones.

例如:

选择ABS(-100)

返回 100 ,而不是 -100

这篇关于会计和数据库设计,存储借方和贷方金额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆