有两个表A\B
A结构如下:
**************
id | field1 
**************
B结构如下:
**************
repid | field1 
**************现在想要写一个delete语句,目的是当A.id=B.repid 的时候删除A里的记录
但是现在repid是nvarchar,而id是int型。请问这个语句我该怎么写
declare @i int
set @i=1
while @i<127657
begin
  delete from A where A.id in (select repid+0 from istpIDrepeat where repid='@i')
  set @i = @i + 1 
end上面的写法不对,请问我该怎么样改正,谢谢!

解决方案 »

  1.   

    delete from A where A.id in (select cast(repid+0 as int) from istpIDrepeat where repid=<127657) 
      

  2.   

    delete from a where cast(id as varchar) in (select cast(repid as varchar) from b)
      

  3.   

    delete A where exists (select 1 from B where cast(B.repid as int) = A.id)
      

  4.   


    delete from A where id in (select cast(repid as int) from istpIDrepeat)
      

  5.   

    delete A where a.id in (select Cast(repid as int) from B )