我面临一个奇怪的问题,我使用了数千次的 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 的示例:0x457874656368203430304120414320636C616D70206D657465722C2041432063757272656E74206D6F64656C20746F206D65657420796F7572206170706C69636174696F6E206E656564732E20203230303020636F756E74204C434420646973706C61792E20204869676820616363757261637920666F722063757272656E74206D6561737572656D656E74732E2020302E3922202832336D6D29206A61772073697A65206163636F6D6D6F646174657320636F6E647563746F727320757020746F203330304D434D2E2020436F6E74696E756974792062656570657220616E642064696F646520746573742E20204461746120686F6C6420616E64206D617820686F6C642E20204F7665726C6F61642070726F74656374696F6E20666F7220616C6C2072616E6765732E20204F76657272616E676520616E64206C6F77206261747465727920696E64696361746F72732E20204175746F72616E67696E672077697468206175746F20706F776572206F66662E0D0A090909090909090909090D0A090909090909090909090D0A090909090909090909090D0A090909090909090909090x457874656368203430304120414320636C616D70206D657465722C2041432063757272656E74206D6F64656C20746F206D65657420796F7572206170706C69636174696F6E206E656564732E20203230303020636F756E74204C434420646973706C61792E20204869676820616363757261637920666F722063757272656E74206D6561737572656D656E74732E2020302E3922202832336D6D29206A61772073697A65206163636F6D6D6F646174657320636F6E647563746F727320757020746F203330304D434D2E2020436F6E74696E756974792062656570657220616E642064696F646520746573742E20204461746120686F6C6420616E64206D617820686F6C642E20204F7665726C6F61642070726F74656374696F6E20666F7220616C6C2072616E6765732E20204F76657272616E676520616E64206C6F77206261747465727920696E64696361746F72732E20204175746F72616E67696E672077697468206175746F20706F776572206F66662E0D0A090909090909090909090D0A090909090909090909090D0A090909090909090909090D0A090909090909090909090x457874656368203430304120414320636C616D70206D657465722C2041432063757272656E74206D6F64656C20746F206D65657420796F7572206170706C69636174696F6E206E656564732E20203230303020636F756E74204C434420646973706C61792E20204869676820616363757261637920666F722063757272656E74206D6561737572656D656E74732E2020302E3922202832336D6D29206A61772073697A65206163636F6D6D6F646174657320636F6E647563746F727320757020746F203330304D434D2E2020436F6E74696E756974792062656570657220616E642064696F646520746573742E20204461746120686F6C6420616E64206D617820686F6C642E20204F7665726C6F61642070726F74656374696F6E20666F7220616C6C2072616E6765732E20204F76657272616E676520616E64206C6F77206261747465727920696E64696361746F72732E20204175746F72616E67696E672077697468206175746F20706F776572206F66662E0D0A090909090909090909090D0A090909090909090909090D0A090909090909090909090D0A09090909090909090909