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

Answers were Sorted based on User's Feedback



how to update a null value field in sql server eg a table contains 3 fields id,name,salary and ..

Answer / 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

how to update a null value field in sql server eg a table contains 3 fields id,name,salary and ..

Answer / ganesh.k

UPDATE Table_Name SET Salary = COALESCE(Salary,0) + 100

(Or)

UPDATE Table_Name SET Salary = ISNULL(Salary,0) + 100

Is This Answer Correct ?    15 Yes 2 No

how to update a null value field in sql server eg a table contains 3 fields id,name,salary and ..

Answer / mohan

create table #temp (eid int, names varchar(10),sal int)

insert into #temp values (111, 'arun', 300)
insert into #temp values(112, 'ddd', 200)

insert into #temp values(113,'ttt',null)

select * from #temp

update #temp
set sal = isnull(sal,0)+ 100

select * from #temp

Is This Answer Correct ?    6 Yes 2 No

how to update a null value field in sql server eg a table contains 3 fields id,name,salary and ..

Answer / mohan

update #temp
set sal = COALESCE(sal+100,100)

Is This Answer Correct ?    4 Yes 1 No

how to update a null value field in sql server eg a table contains 3 fields id,name,salary and ..

Answer / justus

update tablename set salary=100 where salary is null

Is This Answer Correct ?    6 Yes 10 No

how to update a null value field in sql server eg a table contains 3 fields id,name,salary and ..

Answer / dinesh sharma

It Simple
Just Write Down The Query
update table_Name set salary=100 where salary is null

Is This Answer Correct ?    12 Yes 28 No

Post New Answer

More SQL Server Interview Questions

What are the 7 disadvantages to a manual system?

0 Answers  


List the types of recovery model available in sql server?

0 Answers  


Do you know what is a trace frag? Where do we use it?

0 Answers  


do you know what is a deadlock and what is a live lock? How will you go about resolving deadlocks? : Sql server database administration

0 Answers  


What are the 10 characteristics of data quality?

0 Answers  






How to find the second largest salary in the emp database and also How to find 3rd,4th and so on ........ in the emp database plz mail the answer @ mak2786@gmail.com

35 Answers   Oracle, Scend, TechInfini,


Does a server store data?

0 Answers  


What is the difference between IN and EXISTS operators in SQL Server?

9 Answers   ASD Lab, CSC, Intelligroup,


syntex of insert

7 Answers  


what is syntex second or third highest salary. thanks & Regards Dhirendra sinha

7 Answers  


What are the advantages to use stored procedures?

0 Answers   Ernst Young,


What is the difference between rank and dense_rank?

0 Answers  


Categories