Posted By

michanne on 05/05/11


Tagged

StringParsing


Versions (?)

Clean a string


 / Published in: SQL
 

  1. declare @original nvarchar(max), @clean nvarchar(max);
  2.  
  3. SELECT @original = 'wao3u4032qjg(*yDF ]';
  4.  
  5. WITH a AS(
  6. SELECT 1 AS n,substring(@original, 1,1) AS b
  7. union ALL
  8. SELECT n+ 1, substring(@original, n+1,1)
  9. FROM a
  10. WHERE n < len(@original)
  11. )
  12. SELECT @clean = isnull(@clean,'') +
  13. case when ascii(b) <32 OR ascii(b) >=128 then '' + CONVERT(VARCHAR,ASCII(b) ) + ';' else b end
  14. FROM a OPTION (maxrecursion 0);
  15.  
  16. SELECT @clean

Report this snippet  

You need to login to post a comment.