if Exists(select 1 from abc where aid=100)
begin
--如果为空........
print '没有'
end
else
begin
--如果不为空.......
print '有返回结果'
end

解决方案 »

  1.   

    if exists(select a_id from abc where aid=100)
    begin
    --如果为空........
    print '没有
    end
    else
    begin
    --如果不为空.......
    print '有返回结果'
    end
      

  2.   

    错了,写反了if Exists(select 1 from abc where aid=100)
    --如果为空........
    print '有返回结果'
    else
    --如果不为空.......
    print '没有'
      

  3.   

    我晕了
    if Exists(select 1 from abc where aid=100)
    --如果不为空.......
    print '有返回结果'
    else
    --如果为空........
    print '没有'
      

  4.   

    在vc里,我会这么做,用ado 。设置数据源(运行时设),用 SetReocordSource 函数,参数是select  count(*) "a_id" from abc where aid=100。取得RecordSource中的记录,其值就是查询返回的记录数,就可以做判断了。 哈哈,分数拿来。:)
      

  5.   

    因为vc是不能直接用你上面的语句的,没有那么简单。把要sql 嵌入其他语言使用,是不能直接跟你那样写的,具体各种语言不一样!!!分数拿来吧。
      

  6.   

    select a_id from abc where aid=100
    if @@rowcount=0
       print '没有记录!'
    else
       print '有记录!'
      

  7.   

    declare @n int
    set @n=(select 1 from .. where ..)
    if @n is null
    print 'null'
    else 
    print 'not null'
      

  8.   

    select a_id from abc where aid=100
    if @@rowcount>0
     print 'not null'
    else
     print 'null'