If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Update a row with multiple rows

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-05-08, 17:53
ValentinBadea ValentinBadea is offline
Registered User
 
Join Date: Jan 2005
Posts: 9
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 !
Reply With Quote
  #2 (permalink)  
Old 06-05-08, 18:01
ValentinBadea ValentinBadea is offline
Registered User
 
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...
Reply With Quote
  #3 (permalink)  
Old 06-06-08, 04:50
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
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
Twitter | Blog
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On