[英]Using special characters in SQL as string
使用SQL Server 2008
DECLARE @myVariable nvarchar (500)
SET @myVariable = 'select distinct b.*,v.vertrag_id,v.VersicherungsscheinNummer
from CRM_Wifo_GmbH.dbo.vertrag_168 v,temp_universa b
where v.VersicherungsscheinNummer like '%' + b.vsnr + '%
and v.gesellschaft_id in('59','66')'
我必须在变量中设置此类型的值。 我该怎么办? 可能吗? 使用''登录字符串?
你只需要逃避单引号'
使用2个单引号代替''
DECLARE @myVariable nvarchar (500)
SET @myVariable =
N'select distinct b.*,v.vertrag_id,v.VersicherungsscheinNummer
from CRM_Wifo_GmbH.dbo.vertrag_168 v,temp_universa b
where v.VersicherungsscheinNummer like ''%'' + b.vsnr + ''%
and v.gesellschaft_id in(''59'',''66'')'
我也在使用N'
,所以我可以将字符串跨多行
替代解决方案:
DECLARE @myVariable nvarchar (500)
SET @myVariable = 'select distinct b.*,v.vertrag_id,v.VersicherungsscheinNummer from CRM_Wifo_GmbH.dbo.vertrag_168 v,temp_universa b where v.VersicherungsscheinNummer like ' + char(39) + '%' + char(39) + ' + b.vsnr + ' + char(39) + '% and v.gesellschaft_id in(' + char(39) + '59' + char(39) + ',' + char(39) + '66' + char(39) + ')'
但我建议您使用2个单引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.