前面部分略....select a from table2 where a=@tmp
if 这个查询没有结果 begin
insert into table1(a,b,c,d,e) 
select a,b,c,d,0  from inserted
end

解决方案 »

  1.   

    select a from table2 where a=@tmp
    if 这个查询没有结果 begin
    insert into table1(a,b,c,d,e) 
    select a,b,c,d,0  from inserted
    end
    不明白吗
    如果table2没有查询结果,则不用插入数据到table1中.如果找到相关的查询结果则插入数据到相关的表中.
      

  2.   

    首先要问打算在什么时候来判断表空的问题,
    例如是删除操作触发
    其次是问是前出发还是后触发,
    一般是后触发,那么直接用select count(*)或者其他普通判断即可啊
    如果是前触发,需要同时判断原表和inserted表是否有记录
    之后才是插入记录
      

  3.   

    我用update进行触发.我现在就想知道.如果table2没有查询结果,则不用插入数据到table1中.如果找到相关的查询结果则插入数据到相关的表中
      

  4.   

    if @@rowCount=0
      insert into table1(a,b,c,d,e) select a,b,c,d,0  from inserted
      

  5.   

    或者是
    select @count=count(*) from table2 where a=@tmp
    if @count=0
      insert into table1(a,b,c,d,e) select a,b,c,d,0  from inserted