如何将以下SQL语句转换为Update语句
如何将以下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
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')
谢谢,这正是我想要的:)谢谢,这正是我想要的:)。