Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.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

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语句转换为Update语句_Sql_Sql Server_Tsql - Fatal编程技术网

如何将以下SQL语句转换为Update语句

如何将以下SQL语句转换为Update语句,sql,sql-server,tsql,Sql,Sql Server,Tsql,如何将以下SQL语句转换为Update语句: select * from BomStructure BS where Component = '322058-000000' and exists ( select 1 from BomStructure where ParentPart = BS.ParentPart

如何将以下SQL语句转换为Update语句:

select
    * 
from
    BomStructure BS
where
    Component = '322058-000000'
    and
    exists
    (
        select
            1
        from
            BomStructure
        where
            ParentPart = BS.ParentPart
            and
            Component = '322123-301200'
    );
我想

update
    BomStructure BS
set
    StructureOffDate = '2019-09-30'
where 
    Component = '322058-000000'
    and
    exists
    (
        select
            1
        from
            BomStructure
        where
            ParentPart = BS.ParentPart
            and
            Component = '322123-301200'
    );
但是我上面的语法是不正确的。请协助。

我想您需要:

update bs
      set bs.StructureOffDate = '2019-09-30'
from BomStructure bs
where exists (select 1 
              from BomStructure bs1
              where bs1.ParentPart = bs.ParentPart and bs1.Component = '322123-301200'
             );
您的外部筛选器将仅更新作为
组件='322123-301200'
的行,但根据查询,您似乎希望更新
父部分,其中包含
组件='322123-301200'

,我想您需要:

update bs
      set bs.StructureOffDate = '2019-09-30'
from BomStructure bs
where exists (select 1 
              from BomStructure bs1
              where bs1.ParentPart = bs.ParentPart and bs1.Component = '322123-301200'
             );

您的外部筛选器将只更新作为
Component='322123-301200'
的行,但根据查询,您似乎希望更新其中包含
Component='322123-301200'

ParentPart
,看起来您要查找的是更新所有组件的日期“322058-000000”其母零件也具有组件“322123-301200”。如果是这样,下面的查询应该可以做到这一点:

update BomStructure
set StructureOffDate = '2019-09-30'
where Component='322058-000000' and Parentpart in (select distinct Parentpart from BomStructure where Component = '322123-301200')

看起来您要查找的是更新所有组件“322058-000000”的日期,这些组件的父部件也包含组件“322123-301200”。如果是这样,下面的查询应该可以做到这一点:

update BomStructure
set StructureOffDate = '2019-09-30'
where Component='322058-000000' and Parentpart in (select distinct Parentpart from BomStructure where Component = '322123-301200')

谢谢,这正是我想要的:)谢谢,这正是我想要的:)。