0

I need to insert some string with ' in it, for example 'x.y.x', After some research I discovered the following syntax:

table_b.element = 'replace('x.y.x','',''')' 

the problem is that SQL Server gives me an error:

Unclosed quotation mark after the character string ')

How can I solve this case? I spent about 2 hours on this.

Is there an escape character that I need to use?

2 Answers 2

3

You need to write two single quotes:

replace('x.y.x','','''') 

(This is true for all SQL databases)

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

Comments

0

' is escaped with '', so if its a literal string within an SQL statement;

update t set fld = '''x.y.x''' 

If your passing in a value to a procedure for example or your constructing a statement then using your client language you must replace(data, "'", "''") (or use prepared statements)

2 Comments

'replace('x.y.z',"'","''")' gives me a Unclosed quotation mark after the character string ')'
Its unlear what you need? you would rarely need to use replace() within an sql statement to escape anything; if your passing/building a string containing ' then you need to escape it in your client language

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.