繁体   English   中英

SQL替换以及CAST(PromotionRuleData为NVARCHAR(MAX))

[英]SQL Replace and where CAST(PromotionRuleData as NVARCHAR(MAX))

似乎无法编辑我的旧帖子,但我正在尝试执行此SQL脚本

UPDATE Promotions 
set Description = '£5 Off £25 Spend', 
UsageText = '£5 Off £25 Spend',
EmailText = '£5 Off £25 Spend',
PromotionRuleData= '<ArrayOfPromotionRuleBase xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><PromotionRuleBase xsi:type="StartDatePromotionRule"><StartDate>2013-11-18T00:00:00</StartDate></PromotionRuleBase><PromotionRuleBase xsi:type="ExpirationDatePromotionRule"><ExpirationDate>2014-01-13T00:00:00</ExpirationDate></PromotionRuleBase><PromotionRuleBase xsi:type="ExpirationNumberOfUsesPerCustomerPromotionRule"><NumberOfUsesAllowed>1</NumberOfUsesAllowed>    </PromotionRuleBase><PromotionRuleBase xsi:type="MinimumCartAmountPromotionRule"><CartAmount>24.99</CartAmount></PromotionRuleBase></ArrayOfPromotionRuleBase>',
PromotionDiscountData = '<ArrayOfPromotionDiscountBase xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><PromotionDiscountBase xsi:type="OrderPromotionDiscount"><DiscountType>Fixed</DiscountType><DiscountAmount>5.00</DiscountAmount></PromotionDiscountBase></ArrayOfPromotionDiscountBase>'
where Name = 'test1,test2,etc...'

它返回此错误

消息402,第16级,状态1,第1行
数据类型varchar和text在等于运算符中不兼容。

我尝试使用where CAST(PromotionRuleData as NVARCHAR(MAX))

所以这行读为

CAST(PromotionRuleData as NVARCHAR(MAX)) = '<ArrayOfPromotionRuleBase ...

但没有运气。

您不能将字符串文字与SQL Server中的text列进行比较。

数据类型text是哪一列? 您有机会在WHERE子句中使用您的name列吗?

如果是这样,请改用此WHERE

WHERE CAST(Name AS VARCHAR(MAX)) = 'test1,test2,etc...'

或更好的方法是:将您的列转换为更合适的数据类型,例如VARCHAR(n) (除非您确实需要2 GB = 20亿个字符-如果是,则使用VARCHAR(MAX)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM