开发者

CREATE XML SCHEMA COLLECTION problem with simple quotes

开发者 https://www.devze.com 2023-03-20 20:37 出处:网络
I\'m trying to do the following in Microsoft SQL Server: CREATE开发者_Go百科 XML SCHEMA COLLECTION [dbo].[XYZSchema] AS

I'm trying to do the following in Microsoft SQL Server:

CREATE开发者_Go百科 XML SCHEMA COLLECTION [dbo].[XYZSchema] AS 
N'schema content'
GO 

The problem is that schema content contains a quote (') in a regexp and is breaking the instruction:

 N' ..... <xsd:pattern value="\w+([-+.'] ..... '

Is there a way to escape the quote and maintain the correctnes of the regexp, or declare the Expresion of CREATE XML SCHEMA COLLECTION in some other way?


You're writing a varchar (well, nvarchar) literal. The way to escape single quotes within such a literal is to double them up:

N' ..... <xsd:pattern value="\w+([-+.''] ..... '

From Constants:

If a character string enclosed in single quotation marks contains an embedded quotation mark, represent the embedded single quotation mark with two single quotation marks.

0

精彩评论

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