Search code examples
sqlsql-servert-sqlsql-deletedelete-row

How can I delete rows with "Empty Strings" in a column in SQL Server?


I have many rows/records where one of the columns (movieId) is void of any useful values:

enter image description here

Based on the answer here, the following should work:

enter image description here

...but it doesn't, as you can see in the rectangled "no rows affected"

How can I eliminate/delete all the rows with nothing (but empty space) in the MovieId column?


Solution

  • One explanation as to why your IS NULL delete is not working is that the MovieId values are empty string, rather than NULL. Here is an option you can use to handle both NULL and empty string at the same time:

    DELETE
    FROM dbo.ACTORS_MOVIES_M2M
    WHERE COALESCE(MovieId, '') = '';