简体   繁体   中英

Update query using inner join

Why I get the following syntax error in this section of stored procedure :

Incorrect syntax near the keyword 'FROM'.


WITH CTE_Residence_Overtime
    AS
    (
      SELECT * 
      FROM #Residence
    )
    UPDATE t1 
    SET t1.over_time = t1.over_time + CONVERT(TIME, CAST(CTE_Residence_Overtime.overtimeHours AS VARCHAR(2))  
    FROM r_overtime AS t1
    INNER JOIN CTE_Residence_Overtime 
    ON t1.[trans_date] = CTE_Residence_Overtime.[dayDate];

I think you are missing one bracket

WITH CTE_Residence_Overtime
    AS
    (
      SELECT * 
      FROM #Residence
    )
    UPDATE t1 
    SET t1.over_time = t1.over_time + CONVERT(TIME, CAST(CTE_Residence_Overtime.overtimeHours AS VARCHAR(2)))  
    FROM r_overtime AS t1
    INNER JOIN CTE_Residence_Overtime 
    ON t1.[trans_date] = CTE_Residence_Overtime.[dayDate];

You are missing a closing paren on the set :

    SET t1.over_time = t1.over_time +
                       CONVERT(TIME,
                               CAST(CTE_Residence_Overtime.overtimeHours AS VARCHAR(2)
                                   )  
                              )
------------------------------^

One missing parenthesis can make your life quite hectic!

WITH CTE_Residence_Overtime
        AS
        (
          SELECT * 
          FROM #Residence
        )
        UPDATE t1 
        SET t1.over_time = t1.over_time + CONVERT(TIME, CAST(CTE_Residence_Overtime.overtimeHours AS VARCHAR(2)))  
        FROM r_overtime AS t1
        INNER JOIN CTE_Residence_Overtime 
        ON t1.[trans_date] = CTE_Residence_Overtime.[dayDate];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM