Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Select only the numeric values before - in string
v-2muda
<div>I have a string which has numeric characters or string characters at the begining followed by -.</div>
<div> </div>
<div>I want to select data based on following rules</div>
<div> </div>
<div>A. only the numeric value </div>
<div> </div>
<div>B.If any string value present before - then show null\blank</div>
<div> </div>
<div>C.if no numeric value found and no - found at the beginning then show null</div>
<div> </div>
<div><strong>Example A</strong></div>
<div>1. </div>
<div> </div>
<div>Current I/P</div>
<div>
</div>
<div> </div>
<div>2 - hello world</div>
<div> </div>
<div>Desired o/p</div>
<div>
</div>
<div> </div>
<div>2</div>
<div> </div>
<div><strong>ExampleB</strong></div>
<div> </div>
<div>Current I/P</div>
<div>
</div>
<div> </div>
<div>ab -hello world</div>
<div> </div>
<div> </div>
<div>Desired o/p</div>
<div>
</div>
<div> </div>
<div>
<div><strong>ExampleC</strong></div>
<div> </div>
<div>Current I/P</div>
<div>
</div>
<div> </div>
<div>hello world</div>
<div> </div>
<div> </div>
<div>Desired o/p</div>
<div>
</div>
<div> </div>
</div>
Find more posts tagged with
Comments
Matthew L.
<p>You could parse out the value using JavaScript</p>
<pre class="_prettyXprint _lang-js">
var dataRow = "" + row["DATAROW"]; //Convert DataRow to string
var value = parseInt(dataRow.split("-")[0]); //Split string by hyphen (-) and get the numerical integer value
if(!isNaN(parseFloat(value)) && isFinite(value)) //Check value for number
value; //If number, Return value
else
""; //If NaN, Return blank string
</pre>
<p>See attached example.</p>
<p>Note: The example code is in the Data Set as a Computed Column.</p>