<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi All,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I just knew this non printing character stuff was going to come back and bite me…<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I can identify the rows with non printing characters excluding \t, \r and \n.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Now I need to find which characters are being objected to on each row. I may need to know their position as well.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The data in question is a long varchar. But (fortunately) the longest item is under 12000 characters, so we are under the 32000 char varchar conversion limit.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The easiest way I can think of doing this is to do it in a database procedure…<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">create procedure identify_bad_char<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">as declare<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> snapshot_id integer4 not null not default;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> res_note long varchar not null not default;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> msgid integer4 not null not default;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> msg varchar(256) not null not default;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">begin<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> msgid = 0;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> FOR SELECT snapshot_id, res_note INTO :snapshot_id, :res_note<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> FROM basket_snapshot<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> WHERE res_note SIMILAR TO '%[^' + x'09' + x'0a' + x'0d' + '[:print:]]%'<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> DO<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> msgid = msgid + 1;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> msg = 'res_note for snapshot_id = ' + varchar(:snapshot_id) + ' is dodgy.';<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> message :msgid :msg;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> /* Insert manic while loop here and process the line character by character */<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> ENDFOR;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">end;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal">Before I start coding up the manic while loop … does anyone have a suggestion as to how I can do this more efficiently.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The data was probably added to a web form via a cut and paste from a word document, so we’ve picked up things like smart quotes. Hence we may ultimately be interested in replacing multi character sequences with simple ansi equivalents.
I have a suspicion a clean() function is galloping in my direction.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Martin Bowes<span style="font-family:"Courier New""><o:p></o:p></span></p>
</div>
</body>
</html>