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