DECLARE @P1Value varchar(1000) = '2022,2021,2023';
DECLARE @P1valuesrplc nvarchar(1000) = CONCAT('replace(''', @P1Value, ''','','','''''','''''')');
EXEC (@P1valuesrplc)
I get this error when calling EXEC
:
Parse error at line: 1, column: 9: Incorrect syntax near ''2022,2021,2023''.
but if I manually take the value in @P1valuesrplc
and run, it is successful:
select replace('2022,2021,2023',',',''',''')
Output with replacement operation completes successfully
2022','2021','2023
How can I make the exec
command work with the value in variable @P1valuesrplc
?