信息表A,信息抑制表B,在表B中可以定义多条抑制规则,如果符合抑制条件的记录不存入表A,抑制字段有a,b,c,d和起止时间(starttime,endtime),任意抑制字段都可以为空,比如起止时间为空,就不用判断当前时间是否在起止时间内,只判断其他四个字段是否符合即可。如果符合条件,即插入信息表A。求信息过滤的SQL语句。
会的帮个脚本忙,不会的帮的人气忙,来者有分。

解决方案 »

  1.   

    表B如下:
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[B]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[B]
    GOCREATE TABLE [dbo].[B] (
    [ID] [int] IDENTITY (1, 1) NOT NULL ,
    [a] [int] NULL ,
    [b] [int] NULL ,
    [c] [int] NULL ,
    [d] [int] NULL ,
    [StartTime] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
    [EndTime] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL
    ) ON [PRIMARY]
    GO数据:id  a   b   c   d        starttime                  endtime  
    1   1 1   4 3                               
    2   2   7   4 3 2010-10-1  0:00:00 2010-10-1  0:00:00
    3  -1 6   4 3
    4  -1 6   3 -1                                
      

  2.   

    表A的结构就不用了吧,判断了之后,直接insert表A就行了
      

  3.   

    是这个样子吗declare @a int , @b int,@c int,@d int,@s datetime,@e datetime
    if not exists(select 1 from b 
    where a=isnull(@a,a) and b=isnull(@b,b) and c=isnull(@c,c) and d=isnull(@d,d)
    and StartTime>=isnull(@s,StartTime) and EndTime<=isnull(@e,EndTime)
    )
    begin
    i nsert a select @a,@b,@c ,@d ,@s ,@e 
    end
      

  4.   

    declare @a int , @b int,@c int,@d int,@s datetime,@e datetime
    if not exists(select 1 from b 
    where a=isnull(@a,a) and b=isnull(@b,b) and c=isnull(@c,c) and d=isnull(@d,d)
    and StartTime>=isnull(@s,StartTime) and EndTime<=isnull(@e,EndTime)
    )
    begin
    insert a select @a,@b,@c ,@d ,@s ,@e 
    end