时间:2022-01-06 09:20:12 | 栏目:MsSql | 点击:次
示例一:
包含SQL拼接字符串的存储过程:
Create Procedure Test @TestID int As Declare @s nvarchar(800) Set @s='Select * From dbo.Categories where CategoryID='''+cast(@TestID as varchar)+'''' print @s exec(@s)
执行:
exec Test @TestID=1
执行结果:
示例二:
包含SQL 字符串的存储过程:
Create Procedure Test @TestID int As Declare @s nvarchar(800) Set @s='Select * From dbo.Categories where CategoryID='+''''+cast(@TestID as varchar)+'''' print @s exec(@s)
执行:
exec Test @TestID=1
执行结果: