sql根据传入参数确定选择前几条数据的存储过程

sql代码:

USE [BeijingAgricultureDB] GO DECLARE @return_value int EXEC @return_value = [dbo].[SelectTopNNotifications] @num = 2 SELECT 'Return Value' = @return_value GO

其他示例:

/* Show not having access to variables from the calling batch. */ DECLARE @CharVariable CHAR(3) SET @CharVariable = 'abc' /* sp_executesql fails because @CharVariable has gone out of scope. */ sp_executesql N'PRINT @CharVariable' GO /* Show database context resetting after sp_executesql completes. */ USE pubs GO sp_executesql N'USE Northwind' GO /* This statement fails because the database context has now returned to pubs. */ SELECT * FROM Shippers GO

DECLARE @IntVariable INT DECLARE @SQLString NVARCHAR(500) /* Build and execute a string with one parameter value. */ SET @IntVariable = 35 SET @SQLString = N'SELECT * FROM pubs.dbo.employee WHERE job_lvl = ' + CAST(@IntVariable AS NVARCHAR(10)) EXEC(@SQLString) /* Build and execute a string with a second parameter value. */ SET @IntVariable = 201 SET @SQLString = N'SELECT * FROM pubs.dbo.employee WHERE job_lvl = ' + CAST(@IntVariable AS NVARCHAR(10)) EXEC(@SQLString)

DECLARE @IntVariable INT DECLARE @SQLString NVARCHAR(500) DECLARE @ParmDefinition NVARCHAR(500) /* Build the SQL string once. */ SET @SQLString = N'SELECT * FROM pubs.dbo.employee WHERE job_lvl = @level' /* Specify the parameter format once. */ SET @ParmDefinition = N'@level tinyint' /* Execute the string with the first parameter value. */ SET @IntVariable = 35 EXECUTE sp_executesql @SQLString, @ParmDefinition, @level = @IntVariable /* Execute the same string with the second parameter value. */ SET @IntVariable = 32 EXECUTE sp_executesql @SQLString, @ParmDefinition, @level = @IntVariable

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值