简体   繁体   中英

Update one particular cell in MS SQL

I have table like this

Name      Answer
 A -------  Y
 B -------  N
 C  ------  N
 D  ------  Y
 E  ------  Y

and my problem is I want to update only cells which have 'Y', not updating whole answer column. What i have tried is

UPDATE TABLE1
        SET Answer = 'N' 
WHERE userID=1;

this update all the answers, I want to update only 'Y'

I think this is what you meant? You want to update all answers for 'User 1' where he has answered 'Y'?

UPDATE TABLE1 SET Answer = 'N' WHERE userID=1 AND Answer = 'Y';

尝试此操作,您可以使用答案值在答案列上添加答案。

UPDATE TABLE1 SET Answer = 'N' WHERE Answer = 'Y' 

Do:

UPDATE TABLE1 SET Answer = 'N' 
WHERE userID=1 
AND Answer = 'Y'

try this..i''m not sure if this can be done without creating a new table...should be possible i guess

 select * into Table2 from Table1
 UPDATE TABLE2 SET Answer = case when userID=1 then 'N' else Answer end
 from table1 as a inner join table  table2 as b on a.name=b.name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM