Solved

Update table using MySQL

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

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

763 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