0

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?

3 Answers 3

2

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, '') = '';
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Both worked; I'm going to play Robin Hood and give the answer to you but the upcoming Bounty to Clint Eastwood
@B.ClayShannon I posted first actually. Don't know if you count that as a criterion towards deciding which answer to accept.
1

Maybe this?

DELETE
FROM dbo.ACTORS_MOVIES_M2M
WHERE NULLIF(MovieId, '') IS NULL;

Comments

1

Note that your example above seems to have multiple spaces rather than just a blank value.

You can therefore delete them with something similar to above, but with a trim.

FROM dbo.ACTORS_MOVIES_M2M
WHERE LTRIM(MovieId) = '' OR Movie_ID IS NULL;

You could also use the COALESCE/NULLIF options above e.g.,

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.