有点疑惑
@tablename什么类型,字符串?
select * from 'yourtable' 会不会出现这种情况?

解决方案 »

  1.   

    是不是因为TableName与内部变量名冲突了?换其他名字看看,比如MyTableName
      

  2.   

    表不能用变量的。可以执行字符串啊,
    Exec('select * from A')
    执行字符串的功能很大的哦
      

  3.   

    xfei,不懂你的意思
    能说明白点吗?
    我是在存储过程里操作啊,
      

  4.   

    xfei,你好
    EXEC返回什么值???
    怎么取执行过后,得到的数据集??
      

  5.   

    用@@rowcount判断:declare @sqlstr varchar(200)
    select @sqlstr='select * from '+@tablename+' where yf='+@yf+' and nf='+@nf
    exec(@sqlstr)
    if @@rowcount=0
    begin
      select @out=1
    end