用一条sql语句好象不行,用存储过程把

解决方案 »

  1.   

    delete a from b where A.field1=B.field1 and a.field2=B.field2
      

  2.   

    declare @total int,@lost int,@sale int,@id varchar(50)
    declare c_sale cursor for select a.id  from a,b where a.id=b.id1 and a.filed2=b.filed2 
    open c_sale
    fetch c_sale into @id
    while @@fetch_status=0
        begin
          delete from a where id=@id
          
          fetch next from c_sale into @id
        end
    close c_sale
    deallocate c_sale
    go
      

  3.   

    Delete From 表A Where Fields1 in (Select Fields1 From A,B Where A.field1=B.field1 and a.field2=B.field2)
      

  4.   

    delete A from A, B where A.field1=B.field1 and a.field2=B.field2
      

  5.   

    declare @Fields1 varchar(20), @Fields2 varchar(20), @Fields3 varchar(20),
            @Max1 int, @Min1 int, @Max2 int, @Min2 int
    Create Table #33 (id(自动加一), Fields3 int)
    Select @Max1=Max(表A中最大的自动加一的ID号) From A
    Set @Min1 = 1
    While @Min1<=@Max1
      begin
        Select @Fields1=Fields1, @Fields2=Fields2 From A Where 自动加一的ID号 = @Min1
        Insert #33 (Fields2) Select Fields2 From B Where Fields1 = @Fields1
        Select @Max2=Max(id) From #33
        Set @Min2 = 1
        Wihle @Min2<=@Max2
          begin      
            Select @Fields3=Fields3 From #33 Where ID = @Min2
            if @Fields3=@Fields@ then
              begin
                Delete From A Where 自动加一的ID号 = @Min1
              end;
            Set @Min2 = @Min2 +1 
          end; 
        Set @Min1 = @Min1 +1 
      end;
      

  6.   

    这个地方错了Insert #33 (Fields2) Select Fields2 From B Where Fields1 = @Fields1
    应该是      Insert #33 (Fields3) Select Fields2 From B Where Fields1 = @Fields1
    我的电脑没装SQL而且好久没用了,比较生疏,
    如果答的不好,不要见怪,
      

  7.   

    declare @Fields1 varchar(20), @Fields2 varchar(20), @Fields3 varchar(20),
            @Max1 int, @Min1 int, @Max2 int, @Min2 int
    Create Table #33 (id(自动加一), Fields3 int)
    Select @Max1=Max(表A中最大的自动加一的ID号) From A
    Set @Min1 = 1
    While @Min1<=@Max1
      begin
        Select @Fields1=Fields1, @Fields2=Fields2 From A Where 自动加一的ID号 = @Min1
        Create Table #33 (id(自动加一), Fields3 int)
        Insert #33 (Fields2) Select Fields2 From B Where Fields1 = @Fields1
        Select @Max2=Max(id) From #33
        Set @Min2 = 1
        Wihle @Min2<=@Max2
          begin      
            Select @Fields3=Fields3 From #33 Where ID = @Min2
            if @Fields3=@Fields@ then
              begin
                Delete From A Where 自动加一的ID号 = @Min1
              end;
            Set @Min2 = @Min2 +1 
          end; 
        Drop table #33
        Set @Min1 = @Min1 +1 
      end;
      

  8.   

    测试语句:
    create Table A
    (
      aa varchar(2),
      bb int
    )create Table B
    (
      aa varchar(2),
      bb int
    )insert into a
    select 'aa',8
    union
    select 'bb',4insert into b
    select 'aa',7
    union
    select 'bb',4 
    执行语句:
    delete a from a,b
    where a.aa = b.aa and a.bb = b.bbselect * from a
    结果集:
    aa 8
      

  9.   

    delete A from B where A.field1=B.field1 and a.field2=B.field2