problem in updating a table...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bravo
    New Member
    • Jul 2007
    • 43

    problem in updating a table...

    hi
    i am having a situation where i have to update a whole column and set one value true and rest false For example If the table have two columns Name and Status respectively...
    Name Status
    aTrue
    bFalse
    cFalse

    and if status of b is set to true now then all other status should be false

    aFalse
    bTrue
    cFalse

    is this possible with only runnign one query or i have to run two query one for updating all to False and then second to update a particular record to True
    any suggestions....
    Thanks in advance
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Originally posted by bravo
    hi
    i am having a situation where i have to update a whole column and set one value true and rest false For example If the table have two columns Name and Status respectively...
    Name Status
    aTrue
    bFalse
    cFalse

    and if status of b is set to true now then all other status should be false

    aFalse
    bTrue
    cFalse

    is this possible with only runnign one query or i have to run two query one for updating all to False and then second to update a particular record to True
    any suggestions....
    Thanks in advance
    Try this:

    [code=sql]

    UPDATE table1 SET status = (CASE WHEN name = 'a' THEN TRUE ELSE FALSE END)

    [/code]

    Comment

    • bravo
      New Member
      • Jul 2007
      • 43

      #3
      thanks a lot amit it worked perfectly....

      Comment

      • amitpatel66
        Recognized Expert Top Contributor
        • Mar 2007
        • 2358

        #4
        You are welcome :) .

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          Originally posted by amitpatel66
          Try this:
          [code=sql]UPDATE table1 SET status = (CASE WHEN name = 'a' THEN TRUE ELSE FALSE END)[/code]
          That is a neat one amitpatel6!

          Ronald

          Comment

          • amitpatel66
            Recognized Expert Top Contributor
            • Mar 2007
            • 2358

            #6
            Originally posted by ronverdonk
            That is a neat one amitpatel6!

            Ronald
            Thanks Ron :) .
            I will take that!! :)

            Comment

            Working...