473,320 Members | 2,189 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Replicating values in a table

I have a table that contains mostly zero entries but has a few
non-zero values scattered randomly in the table as VERSION 1 below.
What I want to do is fill in the zeroed values with copies of the
non-zero values resulting in the modified version of the table as
shown in VERSION 2 below.

In other words, I want to replicate entries following the entries as
originally supplied.

I would like someone to supply me with the MySQL code that can do this
or point me at an example of it.

CREATE TABLE `table1` (
`record_number` int(8) NOT NULL auto_increment,
`field_A` int(11) default NULL,
PRIMARY KEY (`record_number`),
UNIQUE KEY `record_number` (`record_number`)
) TYPE=MyISAM

VERSION 1
1 0
2 0
3 0
4 99
5 0
6 0
7 0
8 0
9 33
10 0
11 0
12 0

VERSION 2
1 0
2 0
3 0
4 99
5 99
6 99
7 99
8 99
9 33
10 33
11 33
12 33

Thanks very much for your help.
Jul 20 '05 #1
1 1477
James E Koehler wrote:
I have a table that contains mostly zero entries but has a few
non-zero values scattered randomly in the table as VERSION 1 below.
What I want to do is fill in the zeroed values with copies of the
non-zero values resulting in the modified version of the table as
shown in VERSION 2 below.


How about pseudocode:

query:
SELECT record_number, field_A
FROM table1
WHERE field_A != 0
ORDER BY record_number DESC

Loop over result set of above query:
{
execute:
UPDATE table1 SET field_A = ?
WHERE field_A = 0 AND record_number > ?
}

Provide the values from the current record in the loop as parameters to
the UPDATE.

You may have been hoping for a complex update statement that would do
the whole thing, but I can't think of one. Sometimes it's better to
make use of a programming language to help you out.

Regards,
Bill K.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nathan Simpson | last post by:
Hi, We have one domain with a mixture of NT PDC's one Win2K DC (which was the first installed) and 4 Windows 2003 DC's. I created our sites as per MS documentation and created the subnets that...
1
by: Justin French | last post by:
Hi all, I've been using CSS for typography for quite some time, but have not looked into it too deep at all in regards to layout. Now is as good a time as any eh? Whilst ultimately I'll...
0
by: nwiebe | last post by:
Hi, does anyone know how to avoid replicating delete statements? I have a table in a source database. This table is pruned occasionally. I'd like to have a copy of this table in a second...
5
by: Derickson | last post by:
I am working with a production runtime Access 2000 db, split front-end and back-end. Running on a network, I need a nightly copy of the backend transferred to a laptop with a temporary network...
2
by: bissatch | last post by:
Hi, I have an HTML structure where each page area is a <div> and identifies with a unique 'id'. Below is the code: <html> <head> <style> #wrap {
0
by: ceadtinneh | last post by:
We're running merge replication between to SQL Server 2000 servers. The application isn't very high volume the setup is pretty vanilla (ie no filters, etc). We have a push subscription set up...
5
by: Radek | last post by:
Hi I'm in need of creating reporting database. What I have to do it is to replicate only half of tables to next database so reports could query only that second database. Unfortunately there is...
1
by: war_wheelan | last post by:
I am replicating an 80GB database between NY can CT and would like to know why table sizes are different between the two. Here is an example of sp_spaceused:: NY IOI_2007_04_23 ...
16
by: aswath | last post by:
hi dere, i have a question. i have an array with replicating values.... al i want to do is delete all replicating values and store the result in another array. eg., String a={1,2,3,3}; String...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.