<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: cannot convert to a numeric in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/cannot-convert-to-a-numeric/qaa-p/13819711#M4850554</link>
    <description>&lt;P&gt;What you are trying to do is skirt one of the fundamental principles of the relational data model, namely that of DOMAINs. SQL Anywhere is (very) forgiving about on-the-fly dynamic type conversion, much more so than other systems, but doing what you are trying to do is still going to cause considerable confusion, grief, and frustration because SQL is &lt;EM&gt;not&lt;/EM&gt; a programming language - it is a query language based on 1st order predicate logic, and the order of operations to compute a query result is not guaranteed. As a user, you wouldn't want it any other way - because reordering the computation to do it efficiently is precisely what a query optimizer is for. &lt;/P&gt;
&lt;P&gt;I have answered similar questions in the past. Look &lt;A href="http://iablog.sybase.com/paulley/?p=2315"&gt;here&lt;/A&gt; for one example.&lt;/P&gt;</description>
    <pubDate>Mon, 13 Feb 2012 13:45:52 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2012-02-13T13:45:52Z</dc:date>
    <item>
      <title>cannot convert to a numeric</title>
      <link>https://community.sap.com/t5/technology-q-a/cannot-convert-to-a-numeric/qaq-p/13819709</link>
      <description>&lt;P&gt;I am trying to find a way to conditionally format datatype a field in a materialized view. Yes it is odd, but trust the fact that we are extracting from other applications, and in one case, there are a series of custom fields that are all string, but can be formatted by the user in the original application for data input.  Now our users are expecting to see the same format that they choose in their original application.  (there are other technical reasons why we don't format this at the time of import into SQLAnywhere).&lt;/P&gt;
&lt;P&gt;I have tried case statements, and even putting one field into two separate subselects, and then "pre"converting non-numeric field data into zeroes.  Nothing has worked.  I have tried everything I can to work around this, and it is either impossible, or there is a bug.  I am only using this on a simple table with 3 records.&lt;/P&gt;
&lt;P&gt;The one field has two nulls and one string value.  I can convert the string value to a 0 in the subselects, but as soon as a I make a conditional statement, e.g. if the column should be string then pull subselect column a, if the column should be numeric, then pull subselect column b
I get:&lt;/P&gt;
&lt;P&gt;Cannot convert 'Christine' to a numeric
SQLCODE=-157, ODBC 3 State="07006"&lt;/P&gt;
&lt;P&gt;Here is a simple example of what I tried to do:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="nb"&gt;select&lt;/SPAN&gt; 
 &lt;SPAN class="k"&gt;if&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="nb"&gt;select&lt;/SPAN&gt; &lt;SPAN class="n"&gt;DataTypeSQL&lt;/SPAN&gt; &lt;SPAN class="n"&gt;from&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"41646d696e"&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="s"&gt;"md_Custom_Field_Definition"&lt;/SPAN&gt; &lt;SPAN class="n"&gt;where&lt;/SPAN&gt; &lt;SPAN class="n"&gt;FieldName&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'CustomFieldEmployee2'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'NUMERIC_2'&lt;/SPAN&gt; &lt;SPAN class="k"&gt;then&lt;/SPAN&gt; &lt;SPAN class="n"&gt;f&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="s"&gt;"Employee Custom Field 02"&lt;/SPAN&gt; &lt;SPAN class="k"&gt;else&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"Employee Custom Field 02b"&lt;/SPAN&gt; &lt;SPAN class="n"&gt;endif&lt;/SPAN&gt; &lt;SPAN class="n"&gt;as&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"xtest"&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;from&lt;/SPAN&gt;
&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="nb"&gt;select&lt;/SPAN&gt;
      &lt;SPAN class="k"&gt;case&lt;/SPAN&gt; &lt;SPAN class="n"&gt;when&lt;/SPAN&gt; &lt;SPAN class="n"&gt;matt&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;C2&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'NUMERIC_2'&lt;/SPAN&gt; &lt;SPAN class="k"&gt;then&lt;/SPAN&gt; &lt;SPAN class="k"&gt;if&lt;/SPAN&gt; &lt;SPAN class="n"&gt;isnumeric&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;nn&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;cn&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="mi"&gt;0&lt;/SPAN&gt; &lt;SPAN class="k"&gt;then&lt;/SPAN&gt; &lt;SPAN class="mi"&gt;0&lt;/SPAN&gt; &lt;SPAN class="k"&gt;else&lt;/SPAN&gt; &lt;SPAN class="n"&gt;nn&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;cn&lt;/SPAN&gt; &lt;SPAN class="n"&gt;endif&lt;/SPAN&gt; &lt;SPAN class="n"&gt;end&lt;/SPAN&gt; &lt;SPAN class="n"&gt;as&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"Employee Custom Field 02"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;
      &lt;SPAN class="k"&gt;if&lt;/SPAN&gt; &lt;SPAN class="n"&gt;matt&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;C2&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'TEXT()'&lt;/SPAN&gt; &lt;SPAN class="k"&gt;then&lt;/SPAN&gt; &lt;SPAN class="n"&gt;nn&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;ct&lt;/SPAN&gt; &lt;SPAN class="n"&gt;endif&lt;/SPAN&gt; &lt;SPAN class="n"&gt;as&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"Employee Custom Field 02b"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;
            &lt;SPAN class="n"&gt;from&lt;/SPAN&gt;&lt;SPAN class="p"&gt;((&lt;/SPAN&gt;&lt;SPAN class="s"&gt;"41646d696e"&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="sx"&gt;qr_mployeeQuery as n&lt;/SPAN&gt;
&lt;SPAN class="sx"&gt;            left outer join(&lt;/SPAN&gt;
&lt;SPAN class="sx"&gt;select v.QQubeCompanyID, v.ListID,&lt;/SPAN&gt;
&lt;SPAN class="sx"&gt;v.CustomFieldEmployee2 as cn,&lt;/SPAN&gt;
&lt;SPAN class="sx"&gt;v.CustomFieldEmployee2 as ct&lt;/SPAN&gt;
&lt;SPAN class="sx"&gt;from "41646d696e".qr_&lt;/SPAN&gt;&lt;SPAN class="n"&gt;EmployeeQuery&lt;/SPAN&gt; &lt;SPAN class="n"&gt;as&lt;/SPAN&gt; &lt;SPAN class="n"&gt;v&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="n"&gt;as&lt;/SPAN&gt; &lt;SPAN class="n"&gt;nn&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;on&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;n&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;QQubeCompanyID&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;nn&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;QQubeCompanyID&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="ow"&gt;and&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;n&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;ListID&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;nn&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;ListID&lt;/SPAN&gt;&lt;SPAN class="p"&gt;))&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2012 04:00:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cannot-convert-to-a-numeric/qaq-p/13819709</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-02-13T04:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: cannot convert to a numeric</title>
      <link>https://community.sap.com/t5/technology-q-a/cannot-convert-to-a-numeric/qaa-p/13819710#M4850553</link>
      <description>&lt;P&gt;I think you mean, that your select shall return numbers and varchars mixed for column xtest. A list like:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="mi"&gt;1&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;2&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;Christine&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;3&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;But how shall SQLA decide which data type to use for xtest? In my opinion you should try to represent all data as strings, like cast(nn.cn as varchar)&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2012 05:23:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cannot-convert-to-a-numeric/qaa-p/13819710#M4850553</guid>
      <dc:creator>MCMartin</dc:creator>
      <dc:date>2012-02-13T05:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: cannot convert to a numeric</title>
      <link>https://community.sap.com/t5/technology-q-a/cannot-convert-to-a-numeric/qaa-p/13819712#M4850555</link>
      <description>&lt;P&gt;Currently that is what we have, however we have to make it easier for users.  e.g. they have to convert the string to number to use it say in an Excel pivot table, etc.
Here is the kicker:  if the user - in the original application - changes the format mask from say text to number, the original application doesn't remove the text based entries (because it is stored as text underneath the hood).  So, we have to do that.&lt;/P&gt;
&lt;P&gt;Another way to put this:  I know that I can't format text to a number if isnumeric = 0.  So I was attempting to create a temporary "container" in which I would change the offending text value to 0.
And then I was attempting to say - outside of the container/subselect - to give me THAT container if we want it formatted as number, or to choose another container / leave it alone if we want it formatted as text.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2012 11:41:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cannot-convert-to-a-numeric/qaa-p/13819712#M4850555</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-02-13T11:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: cannot convert to a numeric</title>
      <link>https://community.sap.com/t5/technology-q-a/cannot-convert-to-a-numeric/qaa-p/13819713#M4850556</link>
      <description>&lt;P&gt;I do not really understand your requirements - nevertheless the &lt;A href="http://sqlanywhere-forum.sap.com/questions/4701"&gt;following FAQ&lt;/A&gt; may help how to return "potential numbers" without getting conversion errors.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2012 12:02:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cannot-convert-to-a-numeric/qaa-p/13819713#M4850556</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2012-02-13T12:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: cannot convert to a numeric</title>
      <link>https://community.sap.com/t5/technology-q-a/cannot-convert-to-a-numeric/qaa-p/13819711#M4850554</link>
      <description>&lt;P&gt;What you are trying to do is skirt one of the fundamental principles of the relational data model, namely that of DOMAINs. SQL Anywhere is (very) forgiving about on-the-fly dynamic type conversion, much more so than other systems, but doing what you are trying to do is still going to cause considerable confusion, grief, and frustration because SQL is &lt;EM&gt;not&lt;/EM&gt; a programming language - it is a query language based on 1st order predicate logic, and the order of operations to compute a query result is not guaranteed. As a user, you wouldn't want it any other way - because reordering the computation to do it efficiently is precisely what a query optimizer is for. &lt;/P&gt;
&lt;P&gt;I have answered similar questions in the past. Look &lt;A href="http://iablog.sybase.com/paulley/?p=2315"&gt;here&lt;/A&gt; for one example.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2012 13:45:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cannot-convert-to-a-numeric/qaa-p/13819711#M4850554</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-02-13T13:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: cannot convert to a numeric</title>
      <link>https://community.sap.com/t5/technology-q-a/cannot-convert-to-a-numeric/qaa-p/13819714#M4850557</link>
      <description>&lt;P&gt;I appreciate the answer.  As I have thought thru this process and looked at related issues, it is becoming clearer to me.  I think my stubbornness got in the way of clear thinking.  We are going to use a different route to achieve the end result.  Thank everybody for their responses.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2012 14:20:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cannot-convert-to-a-numeric/qaa-p/13819714#M4850557</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-02-13T14:20:49Z</dc:date>
    </item>
  </channel>
</rss>

