MSSQL 动态加载 SQL语句 (sp_executesql)
程序员文章站
2022-05-04 15:50:10
...
--同时加载多个参数 declare @aa nvarchar(40) declare @min_lvl tinyint execute sp_executesql N'select job_desc,min_lvl from jobs where job_id=6',N'@aa nvarchar(40) output,@min_lvl tinyint output' ,@aa output,@min_lvl output print @aa print @
--同时加载多个参数
declare @aa nvarchar(40)
declare @min_lvl tinyint
execute sp_executesql N'select job_desc,min_lvl from jobs where job_id=6',N'@aa nvarchar(40) output,@min_lvl tinyint output' ,@aa output,@min_lvl output
print @aa
print @min_lvl
---------------------------------------------------------------------
--只能加载一个参数
declare @aa nvarchar(40)
execute sp_executesql N'select @aa=job_desc from jobs where job_id=6',N'@aa nvarchar(40) output',@aa output select @aa