I'm trying to insert a nvarchar value into a specific column in a table. The value can possibly have reserved words and single quote chars(as in don't).
what I have is:
set @myString= REPLACE(@myString, '''', '''''');
set @ExecStatement = 'INSERT INTO #TempTable('+@ColumnName+') VALUES('''+@myString+''')';
exec (@ExecStatement)
This works for the vast majority of items but I get this error message:
Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark after the character string 'We didn't understand, please resend, or type HE'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'We didn't understand, please resend, or type HE'.
and I'm actually missing the remainder of the text that's supposed to be there. It's supposed to be "We didn't understand, please resend, or type HELP and someone will contact you".
Any help would be greatly appreciated.
SELECT @ExecStatementbefore theexec (@ExecStatement)and show us what the result is?declarestatement.INSERT INTO #TempTable(Col1) VALUES('We didn''t understand, please resend, or type HELP and someone will contact you.')