ms访问默认值 [英] ms access default value

查看:75
本文介绍了ms访问默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ms访问的字段属性中添加''默认值''中的函数,以计算新记录后同一表中字段的平均值?



我尝试这个但是没有工作:



(([col1] + [col2] + [col3] + [col4])/ 4 )



请帮忙。

How can i add a fuction in ''default value'' in field properties in ms access, to calculate the average of fields in the same table after a new record?

I try this but didn''t work:

(([col1]+[col2]+[col3]+[col4])/4)

Please help.

推荐答案

这里有一些有用的信息: HTTP://办公室.microsoft.com / zh-CN / access-help / set-a-default-value-for-field-or-control-mdb-HP005188852.aspx [ ^ ]



您不需要在数据库表中设置字段的默认值,因为,您始终可以在查询中设置默认值 :

Some useful information you''ll find here: http://office.microsoft.com/en-us/access-help/set-a-default-value-for-a-field-or-control-mdb-HP005188852.aspx[^]

You don''t need to set default value for field in database table, because, you can always set "default value" in query:
PARAMETERS p1 INT, p2 INT, p3 INT, p4 INT;
INSERT INTO YourTable (col1, col2, col3, col4, col5)
VALUES(p1, p2, p3, p4, (p1+p2+p3+p4)/4);





但是我想知道你为什么要存储平均值,如果你总能计算它(基于col1-col4值)?



But i''m wondering why do you want to store average value, if you always can calculate it (based on col1-col4 values)?

SELECT col1, col2, col3, col4, (col1+col2+col3+col4)/4 AS col5
FROM YourTable


AFAIK,你可以'' t添加编译时未知的任何默认值:保存数据定义时。这意味着您不能使用需要来自行的数据的计算值,因为尚未设置。



我允许该字段为null,并在我读出时使用存储过程计算出值 - 这样,如果没有指定值,则字段值也是最新的。您的方式只会根据初始值设置一次默认值,这些值可能与读取时的实际值有很大不同。
AFAIK, you can''t add any default value that is not known at compile time: when the data definition is saved. This means you can''t use a calculated value that requires data from the row because that hasn''t been set yet.

I would allow the field to be null, and work out the value using a stored procedure when I read it out - that way, the field value is also up-to-date if no value has been specified. Your way would only set the default once based on the initial values which may be well different to the actual value when you read them.


这篇关于ms访问默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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