[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


sql update command

Posted on 2014-08-04
Medium Priority
Last Modified: 2014-08-04
I am having trouble with a SQL statement trying to update a table.  I am not an experienced programmer so I have been trying to search for an answer.

I am using SQL 2005 and the Microsoft SQL Server Management Studio.

I have two tables JOMAST and JODRTG. It is a one to many relationship. JOMAST will have the job number in it and JODRTG will have several routing numbers in it relating to the job number. In the JODRTG table there are specific rows that will have a number in it relating to the overhead cost. I am trying to update those values by comparing the two tables. I am only interested in updating the "Released" jobs. So I am trying to join the tables by the job number and then filtering for the jomast.fstatus = 'released' and the current field value of the jodrtg.fuovrhdcos = '43.41'.

Below is my current statement:

UPDATE jodrtg
SET jodrtg.fuovrhdcos='46.60'
JOIN [jomast] on jomast.fjobno = jodrtg.fjobno
where jomast.fstatus = 'Released'
and jodrtg.fuovrhdcos = '43.41'

I can do a "Select" using this:

select * from jodrtg
join jomast on jomast.fjobno = jodrtg.fjobno
where jomast.fstatus = 'Released'
and jodrtg.fuovrhdcos = '43.41'

and I can get information back. But when I try to do the "UPDATE", it comes back with

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'JOIN'.

I cannot figure out what I am doing wrong.
Question by:bgfullerton
LVL 41

Accepted Solution

Kyle Abrahams earned 2000 total points
ID: 40239186
UPDATE jodrtg
SET jodrtg.fuovrhdcos='46.60'
from jodrtg
JOIN [jomast] on jomast.fjobno = jodrtg.fjobno
where jomast.fstatus = 'Released'
and jodrtg.fuovrhdcos = '43.41'

I usually alias the tables:
SET j.fuovrhdcos='46.60'
from jodrtg j
JOIN [jomast] k on k.fjobno = j.fjobno
where k.fstatus = 'Released'
and j.fuovrhdcos = '43.41'

Open in new window


Author Closing Comment

ID: 40239201
That did it.

Thank you, Thank you, Thank you.

Thanks for the quick response.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

834 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