0

I am newbie to SQL queries so sorry for this basic question.

I want to insert values into a table where column's value is null

I tried following

INSERT INTO SystemUsers(FilePath)
If @FilePath IS Null
values('C:\Users\Developer\Desktop\MvcApplication8\MvcApplication8\App_Data\Uploads\Lighthouse.jpg')

and

INSERT INTO SystemUsers(FilePath)
where FilePath IS Null
values('C:\Users\Developer\Desktop\MvcApplication8\MvcApplication8\App_Data\Uploads\Lighthouse.jpg')

But that didn't work, how can I insert default values in a column whether column's values are null?

2 Answers 2

9

Maybe what you want is the UPDATE command and not the insert something like this

UPDATE SystemUsers
SET FilePath = 'C:\Users\Developer\Desktop\MvcApplication8\MvcApplication8\App_Data\Uploads\Lighthouse.jpg'
WHERE FilePath is null
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @jjchiw, I missed this.
0
UPDATE SystemUsers
    SET FilePath = 'C:\Users\Developer\Desktop\MvcApplication8\MvcApplication8\App_Data\Uploads\Lighthouse.jpg'
WHERE FilePath is null

Where clause normaly comes after the operation you are doing.

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.