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

which is best institute to learn sql server in ameerpet or sr nagar or maithrivanam?please help

3 Answers  


Which tcp/ip port does the sql server run on? How can it be changed?

0 Answers  


Which is best Subquery (or) joins in sql server? explain why

2 Answers  


What is primary key, unique key, and foreign key?

0 Answers  


Can you explain various data region available in ssrs with their use?

0 Answers  






if a parameter is not send to a stored procedure what type of identifier is to be used in Stp and if that parameter is not feed to the a query inside the Stp how to validate with out useing IF condition

1 Answers   Aviva,


How many types of dimensions are there and what are they? : sql server analysis services, ssas

0 Answers  


Explain the basic concepts of SQL server architecture?

2 Answers   College School Exams Tests,


What is the difference between a stored procedure and a user defined function in sql server?

2 Answers   Millennium,


How can you swap values between two rows in a table using single- SQL statement?

1 Answers   Tavant Technologies, Virtusa,


How can you control the amount of free space in your index pages?

0 Answers  


After using delete statement in sql query to delete some records...to retrieve the deleted records we can get using rollback command but till that where it stores means particular location name i need....(after deleting and rollback )

3 Answers   CarrizalSoft Technologies, iGate,


Categories