只知道exists在查询时,只寻找匹配条件的行,在找到第一个后就返回。你的答案也想不明白,帮你顶一下。

解决方案 »

  1.   

      if NOT EXISTS ( select * from publishers where state = 'NY') --如果括号内的查询有结果集,则条件为假,反之,没有结果集,条件为真。
      begin 
      SELECT 'Sales force needs to penetrate New York et'end  --条件为真时,运行这段代码
      else 
      begin 
      SELECT 'We have publishers in New York' --条件为假时,运行这段代码
      end if not exists(select 1 where 1=2)
    begin 
     print '条件为真'
    end
    else 
    begin
     print '条件为假'
    end
    /*
    条件为真
    */
    if not exists(select 1 where 1=1)
    begin 
     print '条件为真'
    end
    else 
    begin
     print '条件为假'
    end
    /*
    条件为假
    */
      

  2.   

    exist   判断是否有符合条件的数据集,如果有,则为"真"
    not exist   判断是否有符合条件的数据庥,如果无,则为"真"
      

  3.   

    http://www.itpub.net/thread-1089741-1-1.html
      

  4.   

    exists找到第一个匹配记录后就返回,not exists扫描全表
      

  5.   

    EXISTS   检查是否有结果,.不会计算里面的条件
    如:
    IF EXISTS(SELECT  1/0)
    PRINT 'test'
    ELSE 
    PRINT 'test1'/*
    test
    */尽量少用not exists,容易在结果集为空时也会包含进去