我正在编写以下SQL查询来替换double空间。但它给出了错误。有人可以帮忙吗?
以下是代码: -
Select *
From (
select nvcFormName,iEvalID,iFormID,dtCreationTime,dtEvaluatedStartTime,
fltGradScore,nvcFormattedName,iEvaluatorUserID,
iAgentUserID,flScore,iQuestionID,nvcQuestionAnswer
from dbo.vwEvaluationQuestions
inner join dbo.vwUser on iUserId = iAgentUserID where iFormID = 160
) as s
Pivot (min(nvcQuestionAnswer) for iQuestionID in ([23732], replace([23742],' ','') ) as pvt
where dtEvaluatedStartTime > '2017-04-01' and dtEvaluatedStartTime < '2017-04-30'
order by dtEvaluatedStartTime asc
答案 0 :(得分:0)
替换功能用于字符串字符替换。请改用它。单引号将
REPLACE('[23742]','','')
SELECT *
FROM (
SELECT nvcFormName
,iEvalID
,iFormID
,dtCreationTime
,dtEvaluatedStartTime
,fltGradScore
,nvcFormattedName
,iEvaluatorUserID
,iAgentUserID
,flScore
,iQuestionID
,nvcQuestionAnswer
FROM dbo.vwEvaluationQuestions
INNER JOIN dbo.vwUser
ON iUserId = iAgentUserID
WHERE iFormID = 160
) AS s
Pivot(min(nvcQuestionAnswer) FOR iQuestionID IN (
[23732]
,replace('[23742]', ' ', '')
) AS pvt WHERE dtEvaluatedStartTime > '2017-04-01'
AND dtEvaluatedStartTime < '2017-04-30' ORDER BY dtEvaluatedStartTime)