SQL Server: how to insert the ' character
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 a开发者_开发问答n escape character that I need to use?
You need to write two single quotes:
replace('x.y.x','','''')
(This is true for all SQL databases)
'
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)
精彩评论