delete 表1 
where exists(
select 1
from 表2 as t2
where 表1.Bill_ID=t2.Bill_ID
and 表1.Goods_ID=t2.Goods_ID
and t2.State=-1)

解决方案 »

  1.   

    Delete  from 表1 where  Bill_ID in (-1,(select Bill_ID 表2 where State='-1') )
      

  2.   

    --测试数据
    create table 表1(Bill_ID int, Goods_ID int, Amount int)
    create table 表2(Bill_ID int, Goods_ID int, state int)
    insert 表1 select 204, 13, 2
    union  all select 204, 14, 3 
    union  all select 204, 15, 1
    union  all select 204, 16, 5
    insert 表2 select 204, 13, -1  
    union  all select 204, 14, 0
    union  all select 204, 15, 1  
    union  all select 204, 16, -1
      

  3.   

    create table 表2(Bill_ID int,Goods_ID int,State int)
    insert 表2 values(204,13,-1)
    insert 表2 values(204,14,0)
    insert 表2 values(204,15,1)
    insert 表2 values(204,16,-1)
    go
    select * from 表2
    go
    create table 表1(Bill_ID int,Goods_ID int,State int)
    insert 表1 values(204,13,2)
    insert 表1 values(204,14,2)
    insert 表1 values(204,15,1)
    insert 表1 values(204,16,5)
    go
    select * from 表1
    go--select Bill_ID,Goods_ID from 表2 where State=-1--处理过程
    declare @Bill_ID int
    declare @Goods_ID intdeclare Num_Cursor CURSOR FOR                      --游标的定义
    select Bill_ID,Goods_ID from 表2 where State=-1
    open Num_Cursor                                    --打开游标
    fetch next from Num_Cursor into @Bill_ID,@Goods_ID
    while @@FETCH_STATUS=0
    begin
    delete from 表1 where Bill_ID=@Bill_ID and Goods_ID=@Goods_ID
    fetch next  from Num_Cursor  into  @Bill_ID,@Goods_ID      --循环
    end
    close Num_Cursor                                    --关闭游标
    deallocate Num_Cursor                               --销毁游标go--查看结果
    select * from 表1go 
    --删除环境
    drop table 表1drop table 表2
      

  4.   

    DELETE FROM TABLE1
    WHERE ((STR(Bill_ID) + STR(Goods_ID)) IN
              (SELECT str(bill_id) + str(goods_ID)
             FROM table2
             WHERE state = - 1))
      

  5.   

    Delete  from 表1 where  Bill_ID in (select Bill_ID FROM 表2 where State='-1') 我觉得这个方法最简单
      

  6.   

    你漏掉了Goods_ID这个约束条件。楼主,怎么还不结贴啊。等着升级啊。。
      

  7.   

    eprint自定义打印是一个页面套打工具.它直接在IE浏览器中可视化的设计各种复杂的打印模版,
    能够解决在IE浏览器中打印各种复杂的中国式报表及票据。详见: http://218.30.103.110:8080/eprint/index.htm
    方成eform自定义表单平台,纯BS结构.100%开放源码.可以在 http://218.30.103.110:8080/eform/index.html 在线试用.