2010-01-08 28 views
1

下一頁查詢成功運行:檢查空的XML列

select top(100) * from PackageSessionNodes 
where Cast(ContentInteractions as nvarchar) != '' 

下使我錯誤 目標字符串的大小太小,無法表示XML實例

update PackageSessionNodes set ContentInteractions = '<contentinteractions />' 
where Cast(ContentInteractions as nvarchar) = '' 

ContentInteractions是一個XML列。沒有定義DDT。

我該如何解決第二個查詢,以便使用''作爲xml來獲取這些記錄?

我好像SqlServer無法處理存儲在xml列中的空值......但您可以插入它們......那是怎麼回事?

回答

4

問題在於你的CAST。如果不指定nvarchar的長度,則在CAST函數中缺省爲30個字符。那麼,你的發言確實說的是

update PackageSessionNodes set ContentInteractions = '<contentinteractions />' 
where Cast(ContentInteractions as nvarchar(30)) = '' 

所以如果ContentInteractions的XML內容序列化到超過30個字符,你得到這個問題。