0

I'm not great at SQL so this question should be very easy to answer :) I have a column titled Grades and all values are currently NULL. I would like to update the Grades column to "No Data" if it's NULL

This is what I have so far: Select (ISNULL(Grade, 'test')) From bleaTest

Thank you in advance!!

5 Answers 5

4
UPDATE bleaTest SET Grades = 'No Data' WHERE Grades IS NULL;
Sign up to request clarification or add additional context in comments.

Comments

3

To update table you can do this

UPDATE bleaTest
SET Grade = 'No data'
WHERE Grade is null;

And to select

Select ISNULL(Grade, 'No Data') Grade From bleaTest

4 Comments

I like COALESCE over ISNULL but that's me.
I like ISNULL over COALESCE
According to this blogs.x2line.com/al/archive/2004/03/01/189.aspx ISNULL is minimally faster but I think that ISNULL is not in the SQL standard while COALESCE is. Not sure about that though.
Since the question is not tied to any database, I think the best way to go is coalesce, since IsNull is not standard.
1

This probably needs to be customized for your setup, but if you actually want to update the table it would look like

update theTable
set Grades = isnull(Grade, 'No Data')

Or alternately

update theTable
set grades = 'no data'
where grades is null

Comments

1

You can use the following SQL statement

UPDATE bleaTest set Grades = 'No Data' WHERE Grades IS NULL;

Comments

0

You can do an Update as said before:

UPDATE bleaTest SET Grades = 'No Data' WHERE Grades IS NULL;

But if you want to prevent new registers to have a NULL value in that column you can use this code to alter the table:

ALTER TABLE bleaTest MODIFY Grades NOT NULL;
ALTER TABLE bleaTest ALTER  Grades SET DEFAULT 'No Data';

the code can chance depending on what database you use.

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.