Solved

Update table using MySQL

Posted on 2014-09-16
2
222 Views
Last Modified: 2014-09-16
I am updating a table I create and the error I get is improper syntax near ' ' line 2.
The table has been created,  the data from the first 2 inserts are there but the update has not done its part
can anyone guide me in the right direction
DROP TABLE IF EXISTS LKLTN;
CREATE TABLE LKLTN(
ToolNumber int,
LastOfLocation int,
MaxOfUploadTime Varchar(20),
JobType Varchar(10),
Company Varchar(50),
Rig Varchar(50),
RigNumber Varchar(20),
City Varchar(50),
State Varchar(60)
);
Insert INTO LKLTN (ToolNumber,LastOfLocation,MaxOfUploadTime,JobType)
SELECT sa.SerialNumber as 'ToolNumber', Max(JobDownholeEquipment.JobID) AS 'LastOfLocation', Max(JobDownholeEquipment.StartTime) AS 'MaxOfUploadTime',
'Job' AS JobType
FROM SerializedAssets AS sa 
INNER JOIN JobDownholeEquipment ON sa.SerialNumber = JobDownholeEquipment.ToolNumber
GROUP BY sa.SerialNumber, sa.ToolType
HAVING sa.ToolType='TN';


INSERT INTO LKLTN(ToolNumber,LastOfLocation,MaxOfUploadTime,JobType)
SELECT ToolAssemblies.ToolNumber AS ToolNumber, MAX(ToolAssemblies.Location) AS 'LastOfLocation', Max(ToolAssemblies.UploadTime) AS 'MaxOfUploadTime', 'Assembly' AS JobType
FROM ToolAssemblies 
GROUP BY ToolAssemblies.ToolNumber;
Update LKLTN <--------Start here
JOIN Job as j ON LKLTN.LastOfLocation = j.JobID;
SET
LKLTN.Company = j.Company,
LKLTN.Rig = j.Rig,
LKLTN.RigNumber =  j.RigNumber, 
LKLTN.WellName = j.WellName,
LKLTN.City = j.City,
LKLTN.State = j.State

WHERE LKLTN.LastOfLocation = j.JobID;

SELECT * FROM LKLTN GROUP BY ToolNumber

Open in new window

0
Comment
Question by:r3nder
2 Comments
 
LVL 45

Accepted Solution

by:
Vitor Montalvão earned 500 total points
Comment Utility
You have a ';' before the SET keyword. Remove it:
Update LKLTN 
JOIN Job as j ON LKLTN.LastOfLocation = j.JobID
SET
LKLTN.Company = j.Company,
LKLTN.Rig = j.Rig,
LKLTN.RigNumber =  j.RigNumber, 
LKLTN.WellName = j.WellName,
LKLTN.City = j.City,
LKLTN.State = j.State
WHERE LKLTN.LastOfLocation = j.JobID;

Open in new window

0
 
LVL 6

Author Closing Comment

by:r3nder
Comment Utility
Thanks Vitor - its always the little things!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now