update - while loop

  • Hi, I am trying to write a stored proc that will allow me to update a column based on the value in another.  Here is my code:

    WHILE

    (SELECT * FROM tbl1 WHERE value1 = 'abc')

    BEGIN

    UPDATE table1 set value2 = '123' where value1 = 'abc'

    END

    I am receiving this error message:

    Msg 4145, Level 15, State 1, Line 2

    An expression of non-boolean type specified in a context where a condition is expected, near 'BEGIN'.

    Can anyone see where the error is in this?

    Thanks in advance.

  •  

    WHILE EXISTS (SELECT * FROM tbl1 WHERE value1 = 'abc')

    BEGIN

    UPDATE table1 set value2 = '123' where value1 = 'abc'

    END

     

    But I don't see how this loop is ever going to end, got a trigger on that table that will update the 2nd column??

  • Yes you're right.  I just realized that.  I only need the update statement.  I am totally making my life more complicated than it needs to be.  Time to go home, thanks ninja.

Viewing 3 posts - 1 through 2 (of 2 total)

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