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--如果不用++,那就是字符了.
declare @a int set @a=10 exec('select top '+@a+' * from 表')
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--如果不用++,那就是字符了.
set @a=10
exec('select top '+@a+' * from 表')
int类型必须转换