教师涨工资,闹鬼老宅,电压表原理图
declare @topcount int
set @topcount = 100
select top (@topcount) * from adventureworks.humanresources.employee
如果有like等字句,一定要拼sql的话,也应该使用sp_executesql来执行,示例如下:
declare @topcount int --定义top 数量
set @topcount = 100
declare @title nvarchar(100) --定义like内容
set @title = '%n%'
declare @selectsql nvarchar(max)
set @selectsql = '
select top (@topcountpar) *
from adventureworks.humanresources.employee
where title like @titlepar' --使用参数化的top和like
--使用sp_executesql 来执行,可以提高效率
exec sp_executesql @selectsql,
n'@topcountpar as int,@titlepar as nvarchar(100)',
@topcountpar = @topcount,@titlepar = @title
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
SQL Server免费版的安装以及使用SQL Server Management Studio(SSMS)连接数据库的图文方法
SQL Server 2017 Developer的下载、安装、配置及SSMS的下载安装配置(图文教程详解)
网友评论