遗忘海岸

江湖程序员 -Feiph(LM战士)

导航

Delete From 带 inner join

Delete from Table From Table inner join TableOther On Table.Id=TableOther.Id
注意上面是两个From

View Code
Declare @rowCount int
Declare @SQL nvarchar(1000)

set @rowCount=0
Set @SQL=''

select @RowCount=count(1) from  KB_Lable_IsScanSync
where IsSync=1

Set @rowcount=cast( (@RowCount * 2) /3 as int)

Set @SQL='
 Delete From KB_Lable_IsScanSync 
 From KB_Lable_IsScanSync s
 inner join 
  (
    select top '+ cast(@rowCount as nvarchar(50))+' RecId from KB_Lable_IsScanSync
    where IsSync=1
    order by RecId 
   ) as t
 on t.RecId=s.RecId
'
Exec(@SQL)

 

posted on 2013-03-18 13:53  遗忘海岸  阅读(5250)  评论(1编辑  收藏  举报