Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 help on update statement

Author  Topic 

balamuruganmca
Starting Member

1 Post

Posted - 2012-10-24 : 20:38:57
dear sir,

i have a problem on updating statement.problem is i have a table named is DEPARTMENT and now i have added new column named QUALITY having 5 rows in which how can i update following item
'goood'
'bad'
'fine'
'nice' at a time using single update instead using a update statament again and again

balamurugan

chadmat
The Chadinator

1974 Posts

Posted - 2012-10-24 : 22:42:37
Use a case statement? I don't think your objective is clear.

-Chad
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-25 : 00:02:11
quote:
Originally posted by balamuruganmca

dear sir,

i have a problem on updating statement.problem is i have a table named is DEPARTMENT and now i have added new column named QUALITY having 5 rows in which how can i update following item
'goood'
'bad'
'fine'
'nice' at a time using single update instead using a update statament again and again

balamurugan


whats the rule for determining which value goes for which department?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-10-25 : 01:09:20
For suppose there are departments 10,20,30,40,50.
Assume that
10,20 departments are good,
30 -------> bad
40 -------> fine
50 -------> nice

To update department table for above requirement, you have write query as follows:
UPDATE Department
SET Quality = CASE WHEN departmneid IN (10,20) THEN 'good'
WHEN departmneid = 30 THEN 'bad'
WHEN departmneid = 40 THEN 'fine'
WHEN departmneid = 50 THEN 'nice'
end



--
Chandu
Go to Top of Page
   

- Advertisement -