Home > DeveloperSection > Forums > SQL - Update multiple cells in one columns with the same ID
Pravesh Singh
Pravesh Singh

Total Post:101

Posted on    September-22-2014 2:52 AM

 Database Database 

 1 Reply(s)
 708  View(s)
Rate this:

I have a table Answer in SQL Server like this:

QuestionID         AnswerID            AnswerContent                                IsTrue

1                              1                              1990                                       True

1                              2                              300$                                       False

1                              3                              1992                                       True

2                              4                              1993                                       False

2                              5                              400$                                       True

2                              6                              600$                                       False

5                              7                              Lion                                        False

5                              8                              Tiger                                      True

5                              9                              Elephant                              False


Because the AnswerID is an auto-increment and I don't know exactly its value when running the query.

So how can I update the AnswerContent column?

Example: I need to update

"Tiger - False" to "Elephant - True"

"Lion - True" to "1992 - False"


--- Update ---


I cannot change the table structure because it's my teacher's order.

Anchal Kesharwani
Anchal Kesharwani

Total Post:10

Posted on    September-22-2014 2:59 AM

hi pravesh,

you need to try this:

You can do it in one shot using the CASE expression. Here is an example:



    AnswerContent = CASE

        WHEN AnswerContent='Tiger' AND IsTrue='False` THEN `Elephant`

        ELSE AnswerContent ---- Keep the value unchanged


,   IsTrue = ... -- Do other columns using the same expression structure

Modified On Sep-22-2014 03:00:52 AM

Don't want to miss updates? Please click the below button!

Follow MindStick