How to convert empty spaces into null values, using SQL Server?

前端 未结 7 1938
無奈伤痛
無奈伤痛 2020-12-14 05:56

I have a table and the columns on this table contains empty spaces for some records. Now I need to move the data to another table and replace the empty spaces with a N

7条回答
  •  借酒劲吻你
    2020-12-14 06:20

    I solved a similar problem using NULLIF function:

    UPDATE table 
    SET col1 = NULLIF(col1, '')
    

    From the T-SQL reference:

    NULLIF returns the first expression if the two expressions are not equal. If the expressions are equal, NULLIF returns a null value of the type of the first expression.

提交回复
热议问题