首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请问select top 有关问题

2012-01-19 
请教select top 问题我知道下面的SQL不可以,请教如何实现以下的同等效果declare@numintset@num1selecttop

请教select top 问题
我知道下面的SQL不可以,请教如何实现以下的同等效果
declare   @num   int
set   @num=1
select   top   @num   *   from   tablename


我也尝试用这种方式:
declare   @num   int,  
@sqls   nvarchar(4000)  
set   @sqls= 'select   top   @num   *from   tableName   '  
exec   sp_executesql   @sqls,N '@num     int   output ',@num   output  
select   @num

不过这不可以在函数里面执行。



[解决办法]
动态Sql不能在函数里执行

如果用Sql2005可以直接写
select top @num * from tablename

热点排行