开发者

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)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜