开发者

SQL Server: how to insert the ' character

开发者 https://www.devze.com 2023-03-05 17:04 出处:网络
I need to insert some string with \' in it, for example \'x.y.x\', After some research I discovered the following syntax:

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消