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
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 |
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 |
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 |
Answer / justus
update tablename set salary=100 where salary is null
Is This Answer Correct ? | 6 Yes | 10 No |
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 |
What are the differences between substr and charindex in sql server.
How many types of triggers in sql server?
how can we use a composite key for two tables and how can we represent it
Please explain the characteristics of a transaction server for example atomicity, consistency, isolation, durability?
Please give me the SP for the below scenario. I have two tables named Table1 and Table2...I need to fetch record by record from Table1 and insert the record in to table2 where the value in the sno column of the table1 is even number.
What is acid db?
How real and float literal values are rounded?
How to rename an existing column with sql server management studio?
How to loop through result set objects using mssql_fetch_array()?
How are SQL Server databases physically stored under Windows 2000?
Is it possible for a stored procedure to call itself or recursive stored procedure?
What are basics of policy management?