Update Query for multiple rows based on Multiple Criteria

  • It is simple query , i dont think it will not work in 2005

  • It was failing every time with a message about not being able to handle multiple trues in the where clause with an OR. The where in clause works well.

  • lersner (4/9/2008)


    It was failing every time with a message about not being able to handle multiple trues in the where clause with an OR. The where in clause works well.

    I think you are leaving something out when you are posting the problem because this works without error:

    [font="Courier New"]CREATE TABLE #Table1

       (

       id INT IDENTITY(1,1),

       FlagEntity INT

       )

      

    DECLARE @i INT,

           @date DATETIME

    SET @date = GETDATE()

    SET @i = 0

          

    WHILE @i <= 10

       BEGIN

           INSERT INTO #table1

               (

               FlagEntity

               )

               SELECT

                   @i

                  

           SET @i = @i + 1

       END

    SELECT * FROM #Table1

      

    UPDATE   #Table1

    SET              FlagEntity = 0

    WHERE     (ID = 1) OR (ID =2)

    SELECT * FROM #table1  

        

    DROP TABLE #Table1

    [/font]

  • I have seen it work, but I have also seen it fail. I don't know why. It was really very strange but putting the IN made it work 100% of the time. Maybe there is a bug I hit, I am not sure, but 2 people here experienced it.

  • Something is very wrong here.

    When both id's are found the code does not work. SQL Server showed an error when both conditions were true. So the code did not work if there was both an id of 1 and an id of 2. That is the actual offending code.

    When both IDs are found? A single row can only have one value in the ID column; how can both be found?

    It was failing every time with a message about not being able to handle multiple trues in the where clause with an OR. The where in clause works well.

    I have seen it work, but I have also seen it fail. I don't know why. It was really very strange but putting the IN made it work 100% of the time. Maybe there is a bug I hit, I am not sure, but 2 people here experienced it.

    Well, was is failing every time or not? You seem to be contridicting yourself. There is nothing wrong with the original query. There is more to the picture here than you are telling us. Do us a favor....get rid of the IN clause and revert the query back to the one that fails (all of the time, some of the time, whatever). Run the query until it fails and post the actual error message back to this forum.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • I wasn't requesting any more help. The in works and works everytime. When I requested the help, the original query was returning an error for me every time I ran it. I was testing it, because someone else in my office experienced the error. I thought it was odd and tried it, and then I saw the same error. I ran it again today, and I was able to make it work. I am using the In, since it has not failed once.

Viewing 6 posts - 16 through 21 (of 21 total)

You must be logged in to reply to this topic. Login to reply