RTRIM没有按预期工作

时间:2014-06-30 13:51:38

标签: sql sql-server trim varbinarymax varcharmax

我面临一个奇怪的问题,我使用过数千次的RTRIM没有按预期工作。它几乎就像最后的字符看起来像空格,但SQL 2008并没有像空格一样对待它们,因此"空格"最后不会被删除。 "空格的数量"每排不同。有没有人有任何想法或遇到过这个?

下面的光标在将内容转换为varchar(max)时选择记录。然后,它应该根据内容键更新记录,同时削减尾随字符并返回varbinary(max)。这是我的光标:

declare @att_id int
declare @content_key nvarchar(50)
declare @content_char varchar(max)
declare @content varbinary(max)

declare cur cursor for
      select a.att_id, b.content_key, CAST(b.content as varchar(max)) as Content from saattachment as a
            join digitalassetcontent as b on b.content_key = a.content_key
                  where a.att_name like '%^^Product Description%'

open cur

Fetch next from cur into 
      @att_id,
      @content_key,
      @content_char

While (@@FETCH_STATUS=0)

Begin
      set @content = (select CAST(RTRIM(@content_char) AS VARBINARY(MAX)))
      update digitalassetcontent set version = version + 1, content = @content where content_key = @content_key
      update i18ndigitalassetcontent set version = version + 1,content = @content where content_key = @content_key
      update saattachment set version = version + 1, att_updated=GETDATE() where att_id = @att_id

Fetch next from cur into
      @att_id,
      @content_key,
      @content_char

end

close cur
deallocate cur

更新:

这digitalassetcontent.conent实施例:0x457874656368203430304120414320636C616D70206D657465722C2041432063757272656E74206D6F64656C20746F206D65657420796F7572206170706C69636174696F6E206E656564732E20203230303020636F756E74204C434420646973706C61792E20204869676820616363757261637920666F722063757272656E74206D6561737572656D656E74732E2020302E3922202832336D6D29206A61772073697A65206163636F6D6D6F646174657320636F6E647563746F727320757020746F203330304D434D2E2020436F6E74696E756974792062656570657220616E642064696F646520746573742E20204461746120686F6C6420616E64206D617820686F6C642E20204F7665726C6F61642070726F74656374696F6E20666F7220616C6C2072616E6765732E20204F76657272616E676520616E64206C6F77206261747465727920696E64696361746F72732E20204175746F72616E67696E672077697468206175746F20706F776572206F66662E0D0A090909090909090909090D0A090909090909090909090D0A090909090909090909090D0A09090909090909090909

0 个答案:

没有答案