Forums

This topic is locked

Updating Multiple Rows

Posted 23 Mar 2007 11:51:22
1
has voted
23 Mar 2007 11:51:22 Puleng Mahlophe posted:
I am try to update multiple rows on a system that has wrong dates, which will affect the profitability and that day to day running of a business. There are a number of records that has the incorrect date and i want to fix that. Changing the records one by one will take me a very long time.

I know that i have to use an update query, but as to how to use it i am clue less.

please help.

Regards
malesh

Replies

Replied 27 Mar 2007 15:38:29
27 Mar 2007 15:38:29 Lee Diggins replied:
Hi Puleng

If you can pull all of the id's of the records with wrong dates, you could use them in an update statement using the IN operator.

update tbl_tablename
set col_date = 'yourdatevaluehere'
where col_date in (select col_id from tbl_tablename where col_date = 'yourwrongdatevaluehere')

This is the kind of thing you'd do, but, obviously test this out on a backup of your database first, do not run directly on a production system unless it's passed the test.

If you need more specific help regarding this, post back with datatbase you're using, the table name(s), column names and the criteria for the wrong date values.

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 03 May 2007 15:53:34
03 May 2007 15:53:34 John Lyle replied:
Good solution ... what about if you want to specify the set of Records that need updating from a multi-select list control rather than a table?

I have tried code along the lines of:-

UPDATE my_table SET my_table.my_column = 1 WHERE (my_table.keyfield_column In (@list_of_id_nums))

setting the parameter
&lt;Parameter Name="@list_of_id_nums" Value='&lt;%# Request.Form["myListControl"] %&gt;' Type="Int" /&gt;

But I get type conversion errors if more than one selection is made. The list control returns a comma separated list of Ints which would work from an SQL perspective - if only the complier would allow it!

Any ideas ?

I'm using Dreamweaver MX with C#





<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Hi Puleng

If you can pull all of the id's of the records with wrong dates, you could use them in an update statement using the IN operator.

update tbl_tablename
set col_date = 'yourdatevaluehere'
where col_date in (select col_id from tbl_tablename where col_date = 'yourwrongdatevaluehere')

This is the kind of thing you'd do, but, obviously test this out on a backup of your database first, do not run directly on a production system unless it's passed the test.

If you need more specific help regarding this, post back with datatbase you're using, the table name(s), column names and the criteria for the wrong date values.

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
&lt;font size="1"&gt;[ Studio MX/MX2004 | ASP -&gt; VBScript/PerlScript/JavaScript | SQL | CSS ]&lt;/font&gt;
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 07 May 2007 23:24:09
07 May 2007 23:24:09 Lee Diggins replied:
Hi John

Exactly the right solution, almost. The single passed value will work with a data type of int, because you're passing a single whole number, however, the multiple values passed will be delimited by a comma ',' and so cannot be an int data type. Pass it as a string and see how you get on.

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>

Reply to this topic