如何将所有记录的空白(null)值替换为 0?

发布于 2024-08-16 20:46:47 字数 180 浏览 3 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

许一世地老天荒 2024-08-23 20:46:47

转到查询设计器窗口,切换到 SQL 模式,然后尝试以下操作:

Update Table Set MyField = 0
Where MyField Is Null; 

Go to the query designer window, switch to SQL mode, and try this:

Update Table Set MyField = 0
Where MyField Is Null; 
等你爱我 2024-08-23 20:46:47

如果您尝试通过查询来执行此操作,那么这就是您的答案:

SELECT ISNULL([字段], 0) FROM [表]

Edit

ISNULL 函数使用不正确 - 此修改版本使用 IIF

SELECT IIF(ISNULL([field]), 0, [field]) FROM [table]

如果您想替换表中的实际值,那么你需要这样做:

UPDATE [table] SET [FIELD] = 0 WHERE [FIELD] IS NULL

If you're trying to do this with a query, then here is your answer:

SELECT ISNULL([field], 0) FROM [table]

Edit

ISNULL function was used incorrectly - this modified version uses IIF

SELECT IIF(ISNULL([field]), 0, [field]) FROM [table]

If you want to replace the actual values in the table, then you'll need to do it this way:

UPDATE [table] SET [FIELD] = 0 WHERE [FIELD] IS NULL
_蜘蛛 2024-08-23 20:46:47

没有“哪里”和“如果”...

Update Table Set MyField = Nz(MyField,0)

without 'where's and 'if's ...

Update Table Set MyField = Nz(MyField,0)
深居我梦 2024-08-23 20:46:47
UPDATE table SET column=0 WHERE column IS NULL
UPDATE table SET column=0 WHERE column IS NULL
木有鱼丸 2024-08-23 20:46:47
UPDATE YourTable SET MyField = 0 WHERE MyField IS NULL

适用于大多数 SQL 方言。我不使用 Access,但这应该可以帮助您入门。

UPDATE YourTable SET MyField = 0 WHERE MyField IS NULL

works in most SQL dialects. I don't use Access, but that should get you started.

も星光 2024-08-23 20:46:47

更好的解决方案是在生成表时使用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.

薄荷港 2024-08-23 20:46:47

以下查询也适用,如果您愿意,则不需要更新查询:

IIF(Column Is Null,0,Column)

The following Query also works and you won't need an update query if that's what you'd prefer:

IIF(Column Is Null,0,Column)
所有深爱都是秘密 2024-08-23 20:46:47

如果您在查找中键入“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.

梦醒时光 2024-08-23 20:46:47

我刚刚遇到了同样的问题,最终找到了适合我的需求的最简单的解决方案。在表属性中,我将不想显示空值的字段的默认值设置为 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.

带上头具痛哭 2024-08-23 20:46:47

我使用两步过程将具有“空白”值的行更改为“空”值作为占位符。

UPDATE [TableName] SET [TableName].[ColumnName] = "0"
WHERE ((([TableName].[ColumnName])=""));

UPDATE [TableName] SET [TableName].[ColumnName] = "Null"
WHERE ((([TableName].[ColumnName])="0"));

I used a two step process to change rows with "blank" values to "Null" values as place holders.

UPDATE [TableName] SET [TableName].[ColumnName] = "0"
WHERE ((([TableName].[ColumnName])=""));

UPDATE [TableName] SET [TableName].[ColumnName] = "Null"
WHERE ((([TableName].[ColumnName])="0"));
比忠 2024-08-23 20:46:47

我会将上面的 SQL 语句更改为更通用。当涉及到大量人口以避免空值时,使用通配符绝不是一个坏主意。

试试这个:

Update Table Set * = 0 Where * Is Null; 

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:

Update Table Set * = 0 Where * Is Null; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文