0

I am facing an problem in replacing the character in sql query. I am using vs 2008. I am trying to replace the Turkish character İ to I.

Works fine:

Select FirstName, REPLACE(FirstName,N'İ','I') replaced 
from Employee where FirstName = N'İAİL'

Fails when used as dynamic statement.

Same query fails to replace in dynamic statement.

DECLARE @SQL NVARCHAR(4000)
SET @SQL = 'Select FirstName, REPLACE(FirstName,N''İ'',''I'') replaced from Employee where FirstName = N'İAİL'
EXEC (@SQL)

Can you let me know why this fails in second condition?

1 Answer 1

2

Copying and pasting into SSMS the syntax highlighting showed you're missing some apostrophes on the end of your statement:

DECLARE @SQL NVARCHAR(4000)
SET @SQL = 'Select FirstName, REPLACE(FirstName,N''İ'',''I'') replaced from Employee where FirstName = N''İAİL'''
EXEC (@SQL)

Dynamic SQL like that with lots of strings is a royal PITA.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.