473,480 Members | 4,939 Online
Bytes | Software Development & Data Engineering Community
Create 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 2851
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_number, ';')
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***@interfold.com> skrev i en meddelelse
news:d3*************************@posting.google.co m...
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
6259
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...
3
1874
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...
1
6676
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...
3
10945
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...
5
2158
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...
4
4805
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....
1
4366
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,...
4
3937
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...
6
7957
by: Romulo NF | last post by:
Greetings again to everyone, Im back to show this grid componenet i´ve developed. With this grid you can show the data like a normal table, remove the rows that you need, add rows, import data,...
7
12032
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
7040
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,...
0
6905
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7041
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6736
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6908
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...
0
5331
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 project—planning, coding, testing,...
1
4772
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...
0
4478
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...
0
2994
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...

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.