Solved

Update table using MySQL

Posted on 2014-09-16
2
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 50

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40325658
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
ID: 40325692
Thanks Vitor - its always the little things!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

724 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