declare @StrTotalSQL nvarchar(3000)
SET @StrTotalSQL='select count(*) from table'
exec(@StrTotalSQL)
if select @StrTotalSQL<>0
begin
    select '有记录'
end
go统计不出来结果呢!select @StrTotalSQL<>0  这里要怎么取出查询语句返回的结果啊!

解决方案 »

  1.   

    declare @StrTotalSQL nvarchar(3000)
    SET @StrTotalSQL='(select count(*) from table)' --加括号
    exec(@StrTotalSQL)
    if select @StrTotalSQL<>0
    begin
        select '有记录'
    end
    go
      

  2.   

    加括号也 不行啊!提示select附件语法错误!
      

  3.   


    if 后面怎么能跟这.select @StrTotalSQLfa返回的是select count(*) from table跟0肯定不相等啊
      

  4.   

    declare @StrTotalSQL nvarchar(3000)
    declare @RC intselect @RC = count(*) from table
    if @RC <> 0
    begin
        select '有记录'
    end
    go
      

  5.   


    declare @StrTotalSQL nvarchar(3000)
    declare @cnt int 
    SET @StrTotalSQL='select @cnt=count(*) from table'
    exec sp_executesql @StrTotalSQL,N'@cnt int output',@cnt output
    if @cnt<>0 
    begin  
    select '有记录' 
    end 
    go
      

  6.   

    不要用EXEC了,EXEC接SQL文的方法根本没有返回值一说的
      

  7.   


    declare @StrTotalSQL nvarchar(3000)select @StrTotalSQL=count(*) from layoutif @StrTotalSQL<>0 
    begin  
    select '有记录' 
    end 
    go
      

  8.   


    declare @intTotal as integerselect @intTotal = COUNT(*) from TABLE if @intTotal<>0    select '有记录'
      

  9.   

    declare @StrTotalSQL nvarchar(3000)
    SET @StrTotalSQL='(select count(*) from department)' --加括号
    exec(@StrTotalSQL)
    if @StrTotalSQL<>'0' --StrTotalSQL是nvarchar类型,将0加个单引号就可以了
    begin
        select '有记录'
    end
    go