Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用多个表更新列时出错_Sql_Sql Server_Tsql - Fatal编程技术网

Sql 使用多个表更新列时出错

Sql 使用多个表更新列时出错,sql,sql-server,tsql,Sql,Sql Server,Tsql,更新列时,我收到异常消息: 关键字“ON”附近的语法不正确 您似乎正在尝试将子查询连接到父查询,但这种格式不可能。而是将其移动到where子句的一部分 注意:我强烈建议您花些时间以一种简洁的逻辑方式布局查询,这样更易于调试 UPDATE item_t0 SET item_t0.p_enddate = DATEADD(day, 10, item_t0.p_enddate) FROM employee item_t0 WHERE EXISTS ( SELECT '1' FRO

更新列时,我收到异常消息:

关键字“ON”附近的语法不正确


您似乎正在尝试将子查询连接到父查询,但这种格式不可能。而是将其移动到where子句的一部分

注意:我强烈建议您花些时间以一种简洁的逻辑方式布局查询,这样更易于调试

UPDATE item_t0 SET
    item_t0.p_enddate = DATEADD(day, 10, item_t0.p_enddate)
FROM employee item_t0
WHERE EXISTS (
    SELECT '1'
    FROM orders item_t2
    -- Move to where clause
    -- ON  item_t2.p_id  =  item_t0.p_subsid
    JOIN departs item_t4 ON item_t4.PK = item_t0.p_contract
    JOIN constantvalues3b item_t1 ON item_t0.p_status = item_t1.PK   
    WHERE item_t0.p_startdate > 'Aug 10, 2020 12:00:00 AM' and item_t0.p_enddate < 'Sep 10, 2020 12:00:00 AM'
    AND item_t1.Code in ('Active')
    AND item_t0.p_planid = 'asdcg'
    AND item_t0.customer = '1234567'

    -- Moved fdrom attemped join
    AND item_t2.p_id  =  item_t0.p_subsid
)

您似乎正在尝试将子查询连接到父查询,但这种格式不可能。而是将其移动到where子句的一部分

注意:我强烈建议您花些时间以一种简洁的逻辑方式布局查询,这样更易于调试

UPDATE item_t0 SET
    item_t0.p_enddate = DATEADD(day, 10, item_t0.p_enddate)
FROM employee item_t0
WHERE EXISTS (
    SELECT '1'
    FROM orders item_t2
    -- Move to where clause
    -- ON  item_t2.p_id  =  item_t0.p_subsid
    JOIN departs item_t4 ON item_t4.PK = item_t0.p_contract
    JOIN constantvalues3b item_t1 ON item_t0.p_status = item_t1.PK   
    WHERE item_t0.p_startdate > 'Aug 10, 2020 12:00:00 AM' and item_t0.p_enddate < 'Sep 10, 2020 12:00:00 AM'
    AND item_t1.Code in ('Active')
    AND item_t0.p_planid = 'asdcg'
    AND item_t0.customer = '1234567'

    -- Moved fdrom attemped join
    AND item_t2.p_id  =  item_t0.p_subsid
)