Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005
    Posts
    9

    Unanswered: Update a row with multiple rows

    Hello !

    I want to create a stored procedure in mysql 5.0 to update one field, with 2 input parameters, old value and new, but in the new one I want to put more then 1 value,

    In fact I want to duplicate a row many times and to update a field in each new row with a different value. Something like this:

    Update tableX set columnX = 'B' where columnX = 'A'
    Update tableX set columnX = 'C' where columnX = 'A'
    Update tableX set columnX = 'D' where columnX = 'A'

    but after first update there is no 'A'.
    I want to keep inalterate others values from row of A

    the procedure I think do something
    procedX(A,B)
    procedX(A,C)
    procedX(A,D)

    I must to mention that I haven't values B, C, D in the same time, they are read sequential from an other file.

    Is there a sql method to do this ?

    Now I read (in VB.NET) a datatable (charged with multiple rows ) and then I replace A from each row from datatable with B, C, D, then I save those new rows, and then remove row with A - but this code is very slowly for a table with 5000 pairs like (A,B) from I read.

    Thank you !

  2. #2
    Join Date
    Jan 2005
    Posts
    9
    In fact I want to duplicate a row and in the new one to change a field with a stored procedure...

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Hmm, very interesting requirements - I'd probe but I just can't be bothered today... (basically, your requirements sound so fishy that your design si probably flawed).

    Anyhow, one method I can think of is to do this
    Code:
    INSERT INTO tablex (field1, field2, field3)
    SELECT TOP 1 field1, field2, @new_value
    FROM   tablex
    WHERE  field3 = @old_value
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •