SQL内部拼接执行SQL语句时,实现变量参数化

exec sp_ExecuteSql执行的SQL语句拼接起是比较麻烦,如果关联的表多拼接过程是很容易出错的,下面这方法非常的好用,而且简单直观

if exists(select * from sysobjects where name=" porc_SeekProttoryProject")

drop  proc  SeekProttoryProject

go

create proc  SeekProttoryProject

@shareSgin int,
 @lotteryTypeId  int,
 @projcetStar varchar(500),
 @term varchar(50)

as

declare @ParmDefinition  nvarchar(500);
   declare @prc_GroupStr nvarchar(600);
   set @prc_GroupStr= N'select * from Yuanbo_OpenAward where TypeCatalog =@TypeCatalog and Trem IN (@Trem);

SET @ParmDefinition = N'@TypeCatalog tinyint,@Trem nvarchar(500)';

exec sp_ExecuteSql @prc_GroupStr, @ParmDefinition,
    @TypeCatalog = @lotteryTypeId,@Trem=@projcetStar

上一篇:【干货】解密监控宝Docker监控实现原理


下一篇:Resharper 检测所有NullReferenceExceptions(空指针)