Solved

Update table using MySQL

Posted on 2014-09-16
2
239 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
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 …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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