sql update command

Posted on 2014-08-04
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 39

    Accepted Solution

    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:
    UPDATE j
    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

    That did it.

    Thank you, Thank you, Thank you.

    Thanks for the quick response.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    SQL Query 18 64
    Passing fieldnames as parameter in stored procedure 4 28
    Start a field with integer 1 7 28
    report c# 9 57
    I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
    When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

    728 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

    21 Experts available now in Live!

    Get 1:1 Help Now