Sql server SQL Server:根据TVP table的值删除表中的记录
我有一个PurchaseStationerDetails和TVP(表值参数)TVP_PurchaseStationeryDetails,我的问题是-->我想删除PurchaseStationeryDetails中TVP表中不可用的记录Sql server SQL Server:根据TVP table的值删除表中的记录,sql-server,Sql Server,我有一个PurchaseStationerDetails和TVP(表值参数)TVP_PurchaseStationeryDetails,我的问题是-->我想删除PurchaseStationeryDetails中TVP表中不可用的记录 只考虑将数据插入 TVP表>/P> DELETE from PurchaseStationeryDetails WHERE PurchaseStationeryMasterId = 1003 AND PurchaseStationery
只考虑将数据插入<强> TVP表>/P>
DELETE from PurchaseStationeryDetails
WHERE PurchaseStationeryMasterId = 1003 AND PurchaseStationeryDetailsId IN
(SELECT PSD.PurchaseStationeryDetailsId FROM PurchaseStationeryDetails PSD, @TVP_PurchaseStationeryDetails TVP_PSD
WHERE PSD.PurchaseStationeryMasterId = TVP_PSD.PurchaseStationeryMasterId AND PSD.PurchaseStationeryDetailsId ! = TVP_PSD.PurchaseStationeryDetailsId AND TVP_PSD.PurchaseStationeryDetailsId != 0)
采购文具详细信息中的列采购文具详细信息-->采购文具详细信息SID、采购文具详细信息
TVP_PurchaseStationeryDetails中的列,-->PurchaseStationeryDetailsId、PurchaseStationeryMasterId…等
在这里,我想从PurchaseStationeryDetails表中删除记录->104,2像这样尝试smth
delete from PSD
from PurchaseStationeryDetails PSD
where not exists (
select 1 from @TVP_PurchaseStationeryDetails TVP_PSD
where PSD.PurchaseStationeryMasterId = TVP_PSD.PurchaseStationeryMasterId
and isnull(PSD.PurchaseStationeryDetailsId,0) = TVP_PSD.PurchaseStationeryDetailsId
)
and PSD.PurchaseStationeryMasterId = 1003
像这样尝试smth
delete from PSD
from PurchaseStationeryDetails PSD
where not exists (
select 1 from @TVP_PurchaseStationeryDetails TVP_PSD
where PSD.PurchaseStationeryMasterId = TVP_PSD.PurchaseStationeryMasterId
and isnull(PSD.PurchaseStationeryDetailsId,0) = TVP_PSD.PurchaseStationeryDetailsId
)
and PSD.PurchaseStationeryMasterId = 1003
尝试使用
左侧
或右侧外部联接
create table #tvp (id int, val int)
insert into #tvp
values
(101, 1), (102, 2),(103,2)
create table #purchase (iden int, value int)
insert into #purchase
values
(101, 1), (102, 2),(103,2),(104,2)
delete p
from #tvp t
right outer join
#purchase p
on (t.val = p.value and t.id = p.iden)
where t.id is null
尝试使用
左侧
或右侧外部联接
create table #tvp (id int, val int)
insert into #tvp
values
(101, 1), (102, 2),(103,2)
create table #purchase (iden int, value int)
insert into #purchase
values
(101, 1), (102, 2),(103,2),(104,2)
delete p
from #tvp t
right outer join
#purchase p
on (t.val = p.value and t.id = p.iden)
where t.id is null
我错过问题了吗?“在TVP表中不可用的”。。。可能只是
不在(选择…
?您没有指定question@Shnugo好的,我会尝试不在回答你我错过了问题吗?“在TVP表中不可用的”。。。可能只是不在(选择…
?您没有指定question@Shnugo好的,我会尝试不在,然后回复你