0

I'm pretty new to SQL. I'm practicing on a dataset I downloaded, unfortunately some int type columns became varchar when I imported them. I need to change them back into int.

I tried to create a temp table, create the correct schema for the table with appropriate datatype for all columns, then dump everything back. I got an int column with a mixture of int and empty strings. How do I convert empty strings to zeros? Thank you.

1 Answer 1

1

With an UPDATE statement like this:

UPDATE tablename
SET columnname = 0
WHERE columnname is null or trim(columnname) = ''

Remove columnname is null if you don't have nulls but empty strings.

Sign up to request clarification or add additional context in comments.

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.