Results 1 to 3 of 3

Thread: SQL Server - Update Query Syntax Error

  1. #1
    Join Date
    Feb 2010
    Posts
    2

    SQL Server - Update Query Syntax Error

    Hello,

    Using SQL Server.

    I am trying to update a table using 2 inner joins.
    I am getting a syntax error with the following:

    Update T1
    set T1.JobCost = (Select Sum(T3.EmployeeCharges)
    From SubJob T1 INNER JOIN Route T2
    ON T1.JobSubNbr = T2.JobSubNbr
    INNER JOIN EmployeeTime T3
    ON T2.RouteNbr = T3.RouteNbr

    All column names are correct.
    There are 3 tables:
    T1 = SubJob PK = JobSubNbr
    T2 = Route PK = RouteNbr & FK = JobSubNbr
    T3 = EmployeeTime FK = RouteNbr

    I want to update the JobCost column in T1 with the Sum of EmployeeCharges in T3 which are assoicate to Routes with that SubJob

    SubJobs have 1 to many Routes
    Routes have 1 to many EmployeeTimes

    Why am I getting a syntax error?

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: SQL Server - Update Query Syntax Error

    You can use SQL JOIN statements to combine data from three or more tables. In many cases, you’ll want to take this a step further and combine data from three or more tables. Let's take a look at the SQL statements that allow you to accomplish this goal for an inner join. You may recall from our basic inner join example that the SQL statement below combines data from the city and state tables in cases where the driver and vehicle are located in the same city:
    SELECT name, tag
    FROM city, stateWHERE city.location = state.location
    This query produced the following results:
    name tag
    -------- --------- ---
    CAL H122JM
    TAL D824HA
    GHT P091YF
    AFF J291QR

  3. #3
    Join Date
    Feb 2010
    Posts
    2

    Re: SQL Server - Update Query Syntax Error

    Thanks for your answer but the question was about the syntax of the Update query. Can you please assist me with that?

Similar Threads

  1. How To Check SQL Syntax in Server
    By DARIELLE in forum Software Development
    Replies: 6
    Last Post: 27-03-2012, 11:37 AM
  2. What is a syntax error?
    By Chrisch in forum Software Development
    Replies: 3
    Last Post: 24-11-2009, 09:53 AM
  3. Syntax for SQL query in JSP.
    By elldeegee in forum Software Development
    Replies: 3
    Last Post: 04-06-2009, 10:44 AM
  4. PHP WordPress Parse Error: syntax error, unexpected $end in
    By Bisujaksha in forum Software Development
    Replies: 2
    Last Post: 22-05-2009, 09:27 AM
  5. LDAP Search Query Syntax
    By etienne in forum Active Directory
    Replies: 1
    Last Post: 06-08-2008, 07:47 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,876,504.10929 seconds with 17 queries