How to replace blank (null ) values with 0 for all records?

后端 未结 11 1580
情歌与酒
情歌与酒 2020-12-30 03:53

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 n

相关标签:
11条回答
  • 2020-12-30 04:43

    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 讨论(0)
  • 2020-12-30 04:47

    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"));
    
    0 讨论(0)
  • 2020-12-30 04:47

    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; 
    
    0 讨论(0)
  • 2020-12-30 04:48

    Better solution is to use NZ (null to zero) function during generating table => NZ([ColumnName]) It comes 0 where is "null" in ColumnName.

    0 讨论(0)
  • 2020-12-30 04:49

    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
    
    0 讨论(0)
提交回复
热议问题