Home >php教程 >php手册 >MSSQL 动态加载 SQL语句 (sp_executesql)

MSSQL 动态加载 SQL语句 (sp_executesql)

WBOY
WBOYOriginal
2016-06-06 20:01:251540browse

--同时加载多个参数 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

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn