簡體   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