473,399 Members | 2,159 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,399 software developers and data experts.

MySQL - Chaining a Series of SQL commands

Hello all,

I am still relatively new to MySQL and databases in general. I am working on populating a mastertable for Human Resource and have developed a series of MySQL commands to accomplish this. I would like to automate this as much as possible.

Is there a way to link several different SQL commands together?

Many commands rely on the command prior to it.

Just for reference, these are the commands that I am using.

(Find new records and insert into Mastertable)
insert into `mastertable2`
select 0302_2500.ssn, 0302_2500.vsssn, 0302_2500.name_ind, 0302_2500.pay_gr_aa, '0302', '30000'
from Mastertable2 right join 0302_2500 on mastertable2.ssn = 0302_2500.SSN
where (((if(mastertable2.ssn=0302_2500.ssn, 0, 1))=1))

(Find records with changes and insert into Transition table)
insert into transition2
select 0302_2500.ssn, 0302_2500.vsssn, 0302_2500.name_ind, 0302.pay_gr_aa, '0302', '1001'
from 0302_2500, mastertable2
where mastertable2.ssn=0302_2500.ssn
and ((((if(mastertable2.vsssn=0302_2500.vsssn, 0, 1))=1))
or (((if(mastertable2.name_ind=0302_2500.name_ind, 0, 1))=1)))

(Match Mastertable to transition and update mastertable Date_end)
Update `mastertable2`, transition2
set mastertable2.date_end=(transition2.date_start-1)
where mastertable2.ssn=transition2.ssn
and mastertable2.date_end=transition2.`Date_end`

(Insert changed records of transition table into mastertable)
Insert into `mastertable2`
select * from `transition2`

(Delete records from transition table)
Delete from transition2 where ssn>0
Jun 27 '07 #1
3 4201
r035198x
13,262 8TB
Hello all,

I am still relatively new to MySQL and databases in general. I am working on populating a mastertable for Human Resource and have developed a series of MySQL commands to accomplish this. I would like to automate this as much as possible.

Is there a way to link several different SQL commands together?

Many commands rely on the command prior to it.

Just for reference, these are the commands that I am using.

(Find new records and insert into Mastertable)
insert into `mastertable2`
select 0302_2500.ssn, 0302_2500.vsssn, 0302_2500.name_ind, 0302_2500.pay_gr_aa, '0302', '30000'
from Mastertable2 right join 0302_2500 on mastertable2.ssn = 0302_2500.SSN
where (((if(mastertable2.ssn=0302_2500.ssn, 0, 1))=1))

(Find records with changes and insert into Transition table)
insert into transition2
select 0302_2500.ssn, 0302_2500.vsssn, 0302_2500.name_ind, 0302.pay_gr_aa, '0302', '1001'
from 0302_2500, mastertable2
where mastertable2.ssn=0302_2500.ssn
and ((((if(mastertable2.vsssn=0302_2500.vsssn, 0, 1))=1))
or (((if(mastertable2.name_ind=0302_2500.name_ind, 0, 1))=1)))

(Match Mastertable to transition and update mastertable Date_end)
Update `mastertable2`, transition2
set mastertable2.date_end=(transition2.date_start-1)
where mastertable2.ssn=transition2.ssn
and mastertable2.date_end=transition2.`Date_end`

(Insert changed records of transition table into mastertable)
Insert into `mastertable2`
select * from `transition2`

(Delete records from transition table)
Delete from transition2 where ssn>0
That can now be done by grouping the statements into a procedure.
Jun 27 '07 #2
That can now be done by grouping the statements into a procedure.
Thanks, thats exactly what I needed. I believe that my biggest problem is figuring out what everything is called :) thanks for the help.
Jun 28 '07 #3
r035198x
13,262 8TB
Thanks, thats exactly what I needed. I believe that my biggest problem is figuring out what everything is called :) thanks for the help.
The more you write the codes the more terms you'll get to know.
Jun 28 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Steve Steward | last post by:
I'm trying to create a generic object that will work for several different types of databases. Does anyone know why this won't work? // Connect to the database $cmd = $this->db_type . "_connect...
23
by: phpfrizzle | last post by:
Hi there, I have a site with products on it. The site has a mysql backend. All products belong to certain series (table series). There can be up to 4 different products (table products)...
4
by: Dave Moore | last post by:
Hi All, I'm looking at using PHP and MySQL for a particular website application. However, I was a bit concerned that if a PHP script went wrong then it would be possible to accidentally delete or...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
175
by: Sai Hertz And Control Systems | last post by:
Dear all, Their was a huge rore about MySQL recently for something in java functions now theirs one more http://www.mysql.com/doc/en/News-5.0.x.html Does this concern anyone. What I...
1
by: Karuna | last post by:
Hi, I am new to MySQL. I want to create a script file which will include a number of commands and execute it, just like we do in Oracle. Can any one tell me how to do it? Suppose I want to create...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
9
realin
by: realin | last post by:
hi guys, well this time i need to ask something related to database and php. I want to make certain insert statements in multiple tables and i want that to do that a more consistent way. Just...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...
0
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...

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.