delete from AAA a where exists (select 1 from AAA where autoid<a.autoid and cBusType=a.cBusType and VouCode=a.VouCode and ID=a.id and dVouDate=a.dVoudate and dKeepDate = a.dkeepdate and iMonth=a.imonth and CinvCode=a.cinvcode and iAInQuantity =a.iainquantity and iAOutQuantity=a.iaoutquantity)
--这样行不
delete from AAA where AutoID not in
(
select min(AutoID),cBusType,cVouCode,ID,dVouDate,dKeepDate,iMonth,CinvCode,iAInQuantity,iAOutQuantity group by cBusType,cVouCode,ID,dVouDate,dKeepDate,iMonth,CinvCode,iAInQuantity,iAOutQuantity
)
delete from AAA a where exists (select 1 from AAA where autoid<a.autoid and cBusType=a.cBusType and VouCode=a.VouCode and ID=a.id and dVouDate=a.dVoudate and dKeepDate = a.dkeepdate and iMonth=a.imonth and CinvCode=a.cinvcode and iAInQuantity =a.iainquantity and iAOutQuantity=a.iaoutquantity)
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: 'a' 附近有语法错误。但是选择却没有错:
SELECT * from AAA a where exists (select 1 from AAA where autoid<a.autoid and cBusType=a.cBusType and VouCode=a.VouCode and ID=a.id and dVouDate=a.dVoudate and dKeepDate = a.dkeepdate and iMonth=a.imonth and CinvCode=a.cinvcode and iAInQuantity =a.iainquantity and iAOutQuantity=a.iaoutquantity)
where AutoID IN(SELECT AutoID from AAA a where exists (select 1 from AAA where autoid<a.autoid and cBusType=a.cBusType and VouCode=a.VouCode and ID=a.id and dVouDate=a.dVoudate and dKeepDate = a.dkeepdate and iMonth=a.imonth and CinvCode=a.cinvcode and iAInQuantity =a.iainquantity and iAOutQuantity=a.iaoutquantity)
)