如何将所有记录的空白(null)值替换为 0?
MS Access:如何将所有记录的空白(null)值替换为 0?
我想这必须使用 SQL 来完成。我可以使用查找和替换将 0 替换为空白,但反之则不行(即使我输入 [Ctrl-空格键] 插入一个空格,也不会“找到”空白。
所以我想我需要执行 SQL我在其中找到 MyField 的空值,然后将它们全部替换为 0。
MS Access: How to replace blank (null ) values with 0 for all records?
I guess it has to be done using SQL. I can use Find and Replace to replace 0 with blank, but not the other way around (won't "find" a blank, even if I enter [Ctrl-Spacebar] which inserts a space.
So I guess I need to do SQL where I find null values for MyField, then replace all of them with 0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
转到查询设计器窗口,切换到 SQL 模式,然后尝试以下操作:
Go to the query designer window, switch to SQL mode, and try this:
如果您尝试通过查询来执行此操作,那么这就是您的答案:
Edit
ISNULL 函数使用不正确 - 此修改版本使用 IIF
如果您想替换表中的实际值,那么你需要这样做:
If you're trying to do this with a query, then here is your answer:
Edit
ISNULL function was used incorrectly - this modified version uses IIF
If you want to replace the actual values in the table, then you'll need to do it this way:
没有“哪里”和“如果”...
without 'where's and 'if's ...
适用于大多数 SQL 方言。我不使用 Access,但这应该可以帮助您入门。
works in most SQL dialects. I don't use Access, but that should get you started.
更好的解决方案是在生成表时使用NZ(空到零)函数 => NZ([列名])
ColumnName 中的“null”为 0。
Better solution is to use NZ (null to zero) function during generating table => NZ([ColumnName])
It comes 0 where is "null" in ColumnName.
以下查询也适用,如果您愿意,则不需要更新查询:
The following Query also works and you won't need an update query if that's what you'd prefer:
如果您在查找中键入“null”并在替换中输入零,则使用查找和替换将起作用...您将收到警告,此操作无法撤消。
Using find and replace will work if you type "null" in the find and put a zero in the replace...you will be warned that this cannot be undone.
我刚刚遇到了同样的问题,最终找到了适合我的需求的最简单的解决方案。在表属性中,我将不想显示空值的字段的默认值设置为 0。超级简单。
I just had this same problem, and I ended up finding the simplest solution which works for my needs. In the table properties, I set the default value to 0 for the fields that I don't want to show nulls. Super easy.
我使用两步过程将具有“空白”值的行更改为“空”值作为占位符。
I used a two step process to change rows with "blank" values to "Null" values as place holders.
我会将上面的 SQL 语句更改为更通用。当涉及到大量人口以避免空值时,使用通配符绝不是一个坏主意。
试试这个:
I would change the SQL statement above to be more generic. Using wildcards is never a bad idea when it comes to mass population to avoid nulls.
Try this: