exec 动态脚本 里面的参数和sp_executesql (注意引号,否则容易异常)
Posted JayZhou97
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了exec 动态脚本 里面的参数和sp_executesql (注意引号,否则容易异常)相关的知识,希望对你有一定的参考价值。
@indexCt int
@DemographicName nvarchar(500)
INSERT INTO #finalTemp
EXEC(‘SELECT a.QuestionId,a.AnswerId, b.Name QuestionName,c.Name OptionName,a.Content,‘[email protected]+‘ Number,‘‘‘[email protected]+‘‘‘ DemographicName FROM dbo.QuestionaireOther_‘[email protected]+‘ 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=‘[email protected]+‘ AND c.LanguageType=‘[email protected]+‘
AND a.PeopleCode IN(SELECT peoplecode FROM dbo.Demographic_‘[email protected]+‘ WHERE ‘[email protected]+‘ )‘)
整形参数 加一个‘‘
字符串 加三个‘‘‘ ‘‘‘
declare @projectid int
INSERT INTO #CrossNodeFinal
SELECT demoid,
demoname,
‘SELECT PersonGuid FROM dbo.SVEmployeeDemographicMapping WHERE ProjectId [email protected] 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 (注意引号,否则容易异常)的主要内容,如果未能解决你的问题,请参考以下文章
sql中写function是不是可以将表名作为参数传入进行动态查询
[转]使用exec和sp_executesql动态执行SQL语句