DECLARE @TableName VarChar(10)   
set @TableName='t1'
exec('select * from '+@TableName+'')

解决方案 »

  1.   

    create table t1(a varchar(10),b varchar(10))insert t1
    select '1','12'
    union all select '2','12'
    union all select '1-4','12'
    union all select '11-55','12'
    union all select '22-55','12'
    union all select '1-1-','12'
    union all select '2-58','12'declare @n int
    set @n=2
    exec('select top '+@n+' * from t1')drop table t1--如果不用++,那就是字符了.
      

  2.   

    declare @a int
    set @a=10
    exec('select top '+@a+' * from 表')
      

  3.   

    不能用变量用exec 接SQL语句吧,注意,int要用数据类型转换.
      

  4.   

    top后面的int不能用参数 还是用exec吧
      

  5.   

    必须使用动态sql,
    int类型必须转换
      

  6.   

    要是再加上WHERE ,该怎么写?