码迷,mamicode.com
首页 > 数据库 > 详细

exec 动态脚本 里面的参数和sp_executesql (注意引号,否则容易异常)

时间:2018-07-16 16:16:48      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:and   lang   join   map   sel   people   形参   number   nvarchar   

@indexCt int
@DemographicName nvarchar(500)
INSERT INTO #finalTemp
EXEC(‘SELECT a.QuestionId,a.AnswerId, b.Name QuestionName,c.Name OptionName,a.Content,‘+@indexCt+‘ Number,‘‘‘+@DemographicName+‘‘‘ DemographicName FROM dbo.QuestionaireOther_‘+@questionaireId+‘ a
LEFT JOIN dbo.SVSpecQuestionsLanguage b
ON a.QuestionId=b.QuestionID
LEFT JOIN dbo.SVSpecQuestionOptionsLanguage c
ON a.AnswerId=c.OptionID
WHERE a.questionType=2 AND b.LanguageType=‘+@languageId+‘ AND c.LanguageType=‘+@languageId+‘
AND a.PeopleCode IN(SELECT peoplecode FROM dbo.Demographic_‘+@projectId+‘ WHERE ‘+@whe+‘ )‘)


整形参数 加一个‘‘
字符串 加三个‘‘‘ ‘‘‘

 

 

 

declare @projectid int


INSERT INTO #CrossNodeFinal
SELECT demoid,
demoname,
‘SELECT PersonGuid FROM dbo.SVEmployeeDemographicMapping WHERE ProjectId =@projectid AND CHARINDEX(‘‘,‘‘+CONVERT(NVARCHAR(50),DemographicID)+‘‘,‘‘,‘‘,‘
+ childlist + ‘,‘‘) >0 ‘,
demoname,
1
FROM #CrossRoot
WHERE rootid =
(
SELECT rootId FROM #RootId WHERE tmpId = 1


);


EXEC sp_executesql @whe, N‘@projectid int‘, @projectid;

exec 动态脚本 里面的参数和sp_executesql (注意引号,否则容易异常)

标签:and   lang   join   map   sel   people   形参   number   nvarchar   

原文地址:https://www.cnblogs.com/jayblog/p/9317816.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!