how to update a null value field in sql server

eg
a table contains 3 fields id,name,salary
and 3 records
salary of 1 record is null
i want update the nullfield

111 arun 300
112 ddd 200
113 ttt null
i want to update table with add 100 to every record include null
after updation
the recrds should be
111 arun 400
112 ddd 300
113 ttt 100

Answer Posted / ganapathi

solution 1:
update table_name set
salary = isnull(salary,0) + 100

solution 2:
update table_name set
salary = case when
salary is null then 100
else salary + 100
end

Is This Answer Correct ?    49 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I create a stored procedure in sql server?

527


As a general practice, it is recommended to have dbo be the owner of all database objects however, in your database you find number of tables owned by a user other than dbo, how could you fix this?

621


What are the new features in sql server 2016?

550


What is an identity column in insert statements?

587


What is tabulation?

564






What is a group function explain with an example?

523


What is inline variable assignment?

607


Why we use trigger in sql server with example?

514


What is the function of inner join?

563


Is truncate autocommit?

565


Can sql server be linked with other servers like oracle?

529


Define synonym?

731


How to create a new schema in a database?

555


What are the difference between primary key and unique key? : sql server database administration

529


Do you know what are the ways available in sql server to execute sql statements?

547