473,604 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to import data into existing rows of a table?

I have moved 665 records off of Filemaker into mysql-4.0.18. I had a
great deal of trouble exporting a text field, possibly because it had
control characters that interferred with my field delimiter (also it
was from a Mac, and I'm new at this.)

So I have a table called invoices and another table called tasks, that
has only an invoice number and the work billed on that invoice number.
To see the work billed along with the other invoice data I have to do
a join, and this works but is clumsy for me. Since tasks.work is a
text field of 'infinite' variety I don't see the sense of keeping it
in a separate table like I would with clients' info; it belongs *in*
the invoice table, not just with it.

Is it possible to import this text data into a field in the invoice
table? I've messed around with this but it always appends the data as
new records. Perhaps I was doing an insert back then. Is the answer
something like 'load data infile 'workdone.csv' into invoices
(workdone);'

The invoices table was filled in a certain order (by invoice number)
and the workdone.csv was exported in the same order, so each invoice
row should get its correct text.

Is this a good thing, or am I thinking too 'flat-file-ish'?

Thanks,

r
Jul 20 '05 #1
3 2871
Reed Loefgren wrote:
Is it possible to import this text data into a field in the invoice
table?


What you want to do is add a field to the invoice table for the task
text, and UPDATE that field with the text value found in the
corresponding record that is currently in the tasks table. This is a
tricky thing to do in SQL, and in general cannot be done in one statement.

I can think of two different techniques to solve cases like this.

One method would be to generate a series of UPDATE statements, each of
which will update the value in one record of the invoice table. You can
even generate these statements as literal text from a select on the
legacy tasks table:
select concat('update invoices set task = \'', T.task_text,
'\' where invoice_number = ', T.invoice_numbe r, ';')
from tasks T;

Capture the output of this query and then run it through mysql as a
script after you create the new column in the invoices table using ALTER
TABLE ADD COLUMN.

The other method would be to create a new table that has the same
structure as the old invoices table, plus an additional column for the
task text. Then fill that table using INSERT based on a join between
the old invoices table and the tasks table.
INSERT INTO invoices_new
SELECT I.*, T.task_text
FROM invoices I INNER JOIN tasks T using (invoice_number );

Then drop the old invoices table, and rename the new invoices table to
simply 'invoices'.

Regards,
Bill K.
Jul 20 '05 #2
....
The other method would be to create a new table that has the same
structure as the old invoices table, plus an additional column for the
task text. Then fill that table using INSERT based on a join between
the old invoices table and the tasks table.
INSERT INTO invoices_new
SELECT I.*, T.task_text
FROM invoices I INNER JOIN tasks T using (invoice_number );

Then drop the old invoices table, and rename the new invoices table to
simply 'invoices'.

Regards,
Bill K.


Bill,

This I'm pretty sure I can do, and it's better than both my scripting
abilities and my understanding right now of inner/outer/left/right
joins.

thanks,

r
Jul 20 '05 #3

"Reed Loefgren" <rl***@interfol d.com> skrev i en meddelelse
news:d3******** *************** **@posting.goog le.com...
I have moved 665 records off of Filemaker into mysql-4.0.18. I had a
great deal of trouble exporting a text field, possibly because it had
control characters that interferred with my field delimiter (also it
was from a Mac, and I'm new at this.)

So I have a table called invoices and another table called tasks, that
has only an invoice number and the work billed on that invoice number.
To see the work billed along with the other invoice data I have to do
a join, and this works but is clumsy for me. Since tasks.work is a
text field of 'infinite' variety I don't see the sense of keeping it
in a separate table like I would with clients' info; it belongs *in*
the invoice table, not just with it.

Is this a good thing, or am I thinking too 'flat-file-ish'?

You are.

One invoice can have multiple tasks, right?

Better get the hang of joins, it is really not that difficult.

Leif
Jul 20 '05 #4

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

Similar topics

3
6264
by: Doug Baroter | last post by:
Hi, One of my clients has the following situation. They use Access DB for data update etc. some business functions while they also want to view the Access data quickly and more efficiently in SQL Server 2000. Huge Access db with over 100 user tables, over 60 MB data. The DTS package that comes with SQL Server 2000 seems pretty "messy" in the sense that it assumes that one needs to do one time import only or accurately it does not...
3
1886
by: grawsha2000 | last post by:
Greetings All, I have a excel file which is originally a sqlserver table that was exported as a excel file. I have added more data to this excel file and now want to import it again to its original table,i.e, it will overwrite current data in the table but with no change in the schema. How should I handle the issue of PKs in the current table that will be over-written. I know sqlserver dose not adjust PKs when data is over-written,...
1
6690
by: Dan | last post by:
Could someone please help me with auto importing a series of data files into an Access table. I tried to follow code given below in a previous messagebut i'm getting error messages. Here's my database stats: Path: C:\Database (contains the database and all the text files to be imported) Text files to import: (SampleData4.txt and SampleData3.txt as testing examples)
3
10966
by: wildbill | last post by:
I have an Excel spreadsheet with 1000+ rows that I need to import into an Access 2002 db once a month or so. I then need to use that information to update any existing records(multiple fields may need updating) and/or add any new records. I figure one way is to just "brute force" it, i.e., import the spreadsheet then run some code to do a sequential read thru the new table and do lookups in the existing table and update whatever fields...
5
2164
by: Konstantin Andreev | last post by:
Recently I became interested, - Are the data, bulk loaded in the table with LOAD utility, consume the same disk space as loaded with IMPORT utility? The answer turned out to be NOT ! Here is a nutshell description of the test. The testing was done at "DB2/LINUX 8.2.3". Tables for tests: F4106 has 5203 rows, 32 columns. F42199 has 1399252 rows, 245 columns.
4
4842
by: Gregor Kovač | last post by:
Hi! When I'm using IMPORT with INSERT_UPDATE I sometimes get SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. I'm not sure why this happens. The problem is that I get rejected rows because of this. Best regards,
1
4384
by: JC | last post by:
I have a table which is replicated for after images only. I tried to do an import using the replace option into the source table with data. For some of the rows, they were not in the import file, so were replaced in the master table as a result of the import. For the replica database table, the "deleted" rows were not removed; they still exist, along with all the new/updated records from the import. Is this a restriction of DProp? ...
4
3944
by: db2admin | last post by:
Hello, If i import data into tables, import will write all warnings in message file and will tell me why any exception row is rejected. I wanted to get exception rows in seperate table which i assume i can not do with import If i use load, i can get exception rows in exception table but now load does not give details in message file on why those rows were exception rows and why they were rejected. How can i achieve both using any of...
6
7983
by: Romulo NF | last post by:
Greetings again to everyone, Im back to show this grid componenet ive developed. With this grid you can show the data like a normal table, remove the rows that you need, add rows, import data, call determined functions, and edit the data already present What will you need to use the grid? A table with standard markup and an ID to call the script that will turn the table into a grid Parameters: tabelaID => id of the table that will...
7
12060
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
0
7997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8280
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5882
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3907
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3955
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1526
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.