Why has CAST(FieldName to float) failed in view but not in SELECT?

I've just solved a problem but I'm still not sure what the problem is!
I have a data (staging) table with all values stored as text. The data is converted to the correct data-type and also aggregated somewhat in a view. A select statement with the conversion works. A select statement with the conversion and aggregation (GROUP
BY) works. Creating a view of the conversion and aggregation works. However, on selecting from the view (e.g. SELECT TOP 1000 * FROM ViewName) it fails saying it cannot convert from varchar to float. There are no visible characters in the field apart from
numbers between 0 and 9, a decimal point and sometimes a leading minus sign (-).
The fix? Cast to money and then cast to float.
The problem? I don't know! What was the problem? Some of the values had up to 10 decimal places. Was that a problem? Was it really an overflow error masquerading as conversion error? The longest strings present were:
-2.609763091
-0.082456066
-0.674010546
-2.563428427
-0.016109637
-0.313600766
-0.104452264
-0.853811384
-0.302529502
-0.000362354
-0.002961949
-0.319269185
-0.001970796
Would really like to know what caused this so I can spot it in future before it happens.
Cheers.
JCEH

One possibility is that the two execution plans are different.  The logical order of the way SQL processes the clauses a SELECT query is FROM, ON, OUTER, WHERE, GROUP BY, CUBE | ROLLUP, HAVING, SELECT, DISTINCT, ORDER BY, TOP.  (Actually that's
what I learned, now there are some additional things like APPLY, but for our purposes we can ignore them).  The important thing to know is that that is the LOGICAL order, but SQL is allowed (and often does) go change that order to anything it wants as
long as it returns the correct result. 
So, for example, if your FROM clause a number of rows and some of those rows contain data which would cause a CAST (or anything else) in the SELECT clause to fail, but those rows are eliminated by your WHERE clause.  Then SQL could do
FROM, WHERE, SELECT and the query works, or
FROM, SELECT, WHERE and the query fails.  And, in general, you cannot control which plan SQL will use.
So, for example, if you have a table named T with two integer columns I and J and some rows in the table have a value of 0 in the column J and you run
SELECT I/J FROM T WHERE J<>0
it might work and you might get a divide by zero error.  So one safe way to handle this is to write your query as
SELECT I/(CASE WHEN J <> 0 THEN J ELSE NULL END) WHERE J<>0
Another way would be to create a temp table and write an insert statement that inserted into that temp table only the rows where J<>0 and then do the query from the temp table.  Since that is two SQL commands, SQL is forced to do them in order,
it cannot combine them and reorder the processing, that would look like
Create Table #T(I int, J int);
Insert Table #T(I, J)
Select I, J FROM T WHERE J<>0;
Select I/J From #T;
Drop Table #T;
You could try doing the equivalent of one of those to your query and see if that makes the problem go away.
Now I know you are going to ask "Why did the view use to work and it doesn't anymore?" and "Why does using the view and the table return different results".  My guess is that you are getting different plans for the view and the table,
why that is, I don't know, it is often difficult to answer that type of question.  My best guess for why the view used to work, then you ALTERED it, and then changed it back to the original form and it fails even though it is exactly the same as the old
view that was working is, when you had the old view, then was a cached execution plan that was working.  That execution plan might have been created a good while ago.  When you ALTERED it, you, of course, got a new plan.  Then when you ALTERED
it back to the original form, it no longer had the plan it had been using, so had to create a new one, and this new plan was different than the old one.
Finally, if this is the cause of your problem, then you are not guaranteed that the convert to money, then to float is a permanent fix.  If you have column headers which cannot be converted to either money or float, then it could be the convert to money
then to float is enough to get SQL to do the WHERE first, then the SELECT.  But there is no guarantee that will be true forever.  Changes in your data distribution and release level of SQL might make that version do the select first and then the
where.
Tom

Similar Messages

  • Why has my ipad mini stoppedaccessing mail and internet but not skype?

    2 days ago my ipad mini 2 suddenly decided to stop being able to access email or use safari to browse the internet when connected to the cellular network - but NOT when connected to wifi. It also only connects to words with friends via wifi as well as other games.
    Oddly enough I am still able to use skype.
    Please help! I have injured my foot and would like to avoid having to track down an Apple store if possible.
    So far I have tried:
    rebooting the normal way,
    resetting the ipad,
    resetting the network settings,
    resetting all settings on the ipad,
    removing the sim card and reinserting it,
    deleting the email account and adding it again -
    all to no avail. Still desperately looking for an answer!

    A restore might help.
    Backup & Restore
    Restore iOS

  • Why has my Photo Stream stopped working?  I have not changed any settings.

    Why has my Photo Stream stopped working?  I have not changed any settings on either my iPhone or my Mac.  I did try to reset them, but with no success.

    FAQs and trouble shooting tips are here - http://www.apple.com/support/icloud/photo-stream/
    Other than that we need more details to possibley help including what "doesn't work", how you tried to restart, any thing else remembering that we can not see your or yoru computer so depend on what you tell us
    LN

  • HT2513 my iCal shows events in the "month" view but not in the "week" view? why is that?

    my iCal shows events in the "month" view but not in the "week" view? why is that? doesnt sync automatically all the time only sometimes

    my iCal shows events in the "month" view but not in the "week" view? why is that? doesnt sync automatically all the time only sometimes

  • Why is my Apple id working on my MacBook but not my iPad?

    Why is my Apple id working on my MacBook but not my iPad? I can log in o.k. on my MacBook, but using the same user name and password on my iPad, I just get the Incorrect Apple ID or Password message.
    on my iPad, I have used the Forgotten Apple ID or Password link and reset the password. Even after I get the successfully reset password message it still gives me the Incorrect Apple ID or Password message!
    In desperation I have restored the iPad to Factory settings. It appears to be running OS 7. something.
    My Macbook is running 10.8.5.
    But the same problme persists.
    Please help

    I am having the same problem. Works fine on the website but telling me it's incorrect on my iPhone

  • Why do I see pictures of a different user but not my own?

    Why do I see pictures of a different user but not my own? Opening organizer in Photoshop Elements for the first time, I see pictures of my husband, but pictures in my picture library are not there. I do not want to see my husband's pictures. And he did not give me sharing permission. What can I do?

    Do you have two different catalogues  (One for you and other one for your husband)
    if yes,
    In Elements organizer go to File>Manage Catalogs and check if you have any catalogue listed of your name.
    if yes, double click on that catalogue and it will open the media on that catalogue.

  • HT1473 I am having to recreate my itunes library and do not understand why prior album artwork appeared in my older library but not the new library?  Is there some way to scan itunes for missing album artwork?

    I am having to recreate my itunes library and do not understand why prior album artwork appeared in my older library but not the new library?  Is there some way to scan itunes for missing album artwork?

    do you have a strongly recommended default "managed" library (the iPhoto preference to "copy imported items to the iPhoto library is in its checked state) or a referenced library - you have unchecked that option?
    It sounds like you have a referenced library and are now experiancing one of the very siginificant drawbacks of a referenced library and one of the many reasons they are strongly not recommended
    Also note that iPhoto '11 may use alises in the originals folder as part of the upgrade
    It is important that we understand exactly what you have and what is not sorking - what error messages you are getting
    You must NEVER make any changes of any sort to the structure of content of the iPhoto library - there are no user servicable parts in it  --  and you can not rebuild yoru librtary - only iPhoto ir iPhoto Library Manager - http://www.fatcatsoftware.com/iplm/ -  can rebuild a library unless you are a SQL programmer and understand the structure that iPhoto uses
    LN

  • Hi. I tried using Pinterest tonight and got a message that I have a bot in my network..what is this, and how do I get rid of it? My phone has been running really slow too on Safari (but not on Google Chrome)

    Hi. I tried using Pinterest tonight and got a message that I have a bot in my network..what is this, and how do I get rid of it? My phone has been running really slow too on Safari (but not on Google Chrome)

    Google changed their menu bar. Firefox hasn't used Google for the default homepage since the Firefox 3.6 versions. Firefox 4+ versions use '''about:home'''.<br />
    http://www.theverge.com/2011/11/29/2598717/google-bar-redesign-rethinks-the-navigation-bar

  • I bought lightroom and need to register my student id, how do i do that, the trial has run out, i have the product code but not the serial number?

    i bought lightroom and need to register my student id, how do i do that, the trial has run out, i have the product code but not the serial number?

    If you purchased a package then there should have been instructions in the box on how to submit your academic credentials. If you purchased online from Adobe then you should have received instructions in an e-mail. But here is a link that might help you. There is a link under Step 2 that will take you to a place where you can enter the information, I think.
    Adobe - Adobe Education Store : Proof of Academic Indentification

  • Why is the ios6 compatible for all the iphones but not all the phones got the all upgrades, for example the panorama camera??

    why is the ios6 compatible for all the iphones but not all the phones got the all upgrades, for example the panorama camera?? this is another reason I am starting to dislike apple. An ipod is able to us an upgrade but not all the phones are? makes sense

    "why is the ios6 compatible for all the iphones"
    Ios 6 is not available for all iphones. Original Iphone and iphone 3 are not supported.
    "but not all the phones got the all upgrades, "
    This is common for most any device/computer.  Not all iphone/computer/device models can handle all of the new features.  Like any device, hardware is limited and cannot always support all new features and software.

  • Why has my form suddenly disappeared from design view?

    My form has just disappeared from 'design view' but if i hit 'live view' it re-appears, the code is all there i just cant view it?

    Ness_quick wrote:
    My form has just disappeared from 'design view' but if i hit 'live view' it re-appears, the code is all there i just cant view it?
    Its because your table code is broken. I had a job this morning wading through it so I eventually selected just the from part - <form>    </form> - which I believe is intact and dumped it in another DW file.
    If you can't find the broken or missing tag/s can I suggest you do this and rebuild the outer table.

  • Task fails on server but not on my development PC

    hi
    I have this annoying error on my server but not in my PC,
    When I run the task from VisualStudio2010 it works perfectly. Then I deploy the package to my SqlServer2012 "Intgegration Services Catalogs" and run the deployed package from the SqlManagementConsole I got the error.
    The source is an oracle DB and the query wich calculate the field "MONJTO_HRSEXTR" do it with this "sum(nvl(h.monto,0)) monto_hrsext" on the select statement.
    I guess the problem is SSIS thinks that the column MONTO_HRSEXTR is "Unicode string[DT_WSTR]" with "lenght=38" and when the conversion process try to cast to Decimal(12,2) it fails. There are 2 big questions here
    1.Why it works on my development PC and not in the server when deployed?
    2.why the "Data Conversion Transtormation Editor" thinks the field is a  Unicode string[DT_WSTR] if that field is a sum result from numerics fields in the oracle table
    Thanks a lot!!! for any Idea
    Salu2 Sergio T

    Hello
    Thanks for your time, I made a modification
    to the package to redirect all rows
    that cause error
    All errors are rows with decimal values
    ​​such as "11.3" "33.44"
    All values ​​are using "," instead of
    "." and that's the problem
    what is strange is that the same source,
    in both cases the same database
    It will be something related to the
    configuration of the oracle client on the Windows
    server? The Oracle is in another server, a unix server.
    I do not know much about oracle.
    I know we use TSNnames for connecting, but I really don't know what to see, any idea??
    thanks again for your time Jan
    Salu2 Sergio T

  • User Authentication Failed via http BUT not with Visual Administrator !!?

    OS : Win 2k3 Server UK * DB : SQL Server 2005
    SAP Netweaver 2004s Application Java
    Hi All,
    Since a couple of days, I have a problem concerning authentication to the java apllication on a SAP Netweaver 2004s.
    Using the user ‘Administrator’, I CAN logon the Visual Administrator tool, with the same user I tried to logon via http://host:port/nwa without success.
    At the beginning, I was thinking about a problem of password then I enabled the emergency user SAP*, the problem was the same. Ok with Visual Administrator but not via http.
    Here is two logs found in folder : D:\usr\sap\SID\JC02\j2ee\cluster\server0\log\system\
         security.3.log
         <i>#1.5#001871E5EA3A00550000006D0000172800043B836D838427#1191335570983#/System/Security/Audit#sap.com/com.sap.security.core.admin#com.sap.security.core.util.SecurityAudit#Guest#0####5aac137070f411dcc513001871e5ea3a#SAPEngine_Application_Thread[impl:3]_11##0#0#Warning#1#com.sap.security.core.util.SecurityAudit#Plain###Guest     | LOGIN.ERROR     | null     |      | Login Method=[default], UserID=[Administrator], IP Address=[192.168.10.125], Reason=[Authentication did not succeed.]#</i>
         server.0.log
         <i>#1.5#001871E5EA3A0052000000130000172800043B835E3661D1#1191335314249#/System/Server/SLDService##com.sap.sldserv.SldServerFrame######c1a349a070f311dcaa68001871e5ea3a#SAPEngine_System_Thread[impl:5]_71##0#0#Warning#1#com.sap.sldserv.SldServerFrame#Plain###Failed to collect SLD data. Failed to send HTTP data: 401 : Unauthorized. Please check if the target SLD system is available and the SLD bridge is started there.#</i>
    &#61664; I tried to connect http://host:port/sld same problem User Authentication Failed
    <b>Do you have an idea for me? Why a user can connect via Visual Administrator and not via the http interface?</b>
    Thanks in advance
    Yves

    Hi,
    I found the solution this last week-end.
    This behavior let's thinking to a problem of authentication.
    But the problem was in SQL, an index was missing in table J2EE_CONFIG, called J2EE_CONFIG_I3
    Cheers
    Yves

  • I can't figure out why this page splits in live preview... but not in the browser?

    I've finally got my site up and it all runs great... except I can't figure out why this one page behaves like it's too wide.
    http://www.johnnez.com/mainbooks.html
    It comes apart in the Live Preview.... but not in the browser preview.
    Thanks for any tips...
    jn

    john nez wrote:
    HTML is a total incrutable mystery to me... a mystery inside a mystery inside a mystery!
    Sounds to me like you've almost cracked it!
    You have one error that could cause problems and that's the stray </blockquote> tag.  Just delete it.
    The alt="" text will show as an error on the validator but that's easy to fix and worth doing.
    Here's an easy article on that: http://www.456bereastreet.com/archive/200412/the_alt_and_title_attributes/
    In one of your CSS files (JonzheaderindexCSS.css) you have this:
    body {
    margin-top: 20px;
    padding: 0;
    color: #666;
    font-family: Verdana, Geneva, sans-serif;
    font-size: 14px;
    line-height: normal;
    background-attachment: fixed;
    background-color: #E1B852;
    background-image: url(../images/orange%20plaid.jpg);
    background-repeat: repeat;
    html { overflow-y: scroll; }
    It should be like this:
    html {
    overflow-y: scroll;
    body {
    margin-top: 20px;
    padding: 0;
    color: #666;
    font-family: Verdana, Geneva, sans-serif;
    font-size: 14px;
    line-height: normal;
    background-attachment: fixed;
    background-color: #E1B852;
    background-image: url(../images/orange%20plaid.jpg);
    background-repeat: repeat;
    It looks like you have that rule repeated further down the page like this:
    html { overflow-y: scroll; }
    There's an extra curly brace there (}) anyway, so it is badly formed but the whole rule and extra curly brace can go.
    You can fix those errors but I have a sneaky suspicion that it isn't gong to solve the issue you describe.
    Fix those issues anyway and post back.  Maybe if you can show a screen shot of what you are seeing in DW it might help?
    Martin
    PS: It's never a good idea to have file names on the web that have spaces in.  Your background rule has this:
    background-image: url(../images/orange%20plaid.jpg);
    That .jpg should be orangeplaid.jpg or orangePlaid.jpg or orange_plaid.jpg and the change should be reflected in the reference to the image so, orangePlaid.jpg should be:
    background-image: url(../images/orangePlaid.jpg);

  • Why is Image in design view but not in browser?

    Why when I insert an image from root folder it shows in design but not in live view or browser? I have opened a new blank html page and still no image will show up.

    Do you have an editable region in your main Template head tags?
    Just so you know.  Making a template out of an HTML document is just about the last step in your design process.
    First build your prototype.html page so that everything performs well in all browsers.  When you're completely satisfied with how it looks, then Save As Template.dwt.
    Add editable regions for content that will change from page to page.
    Spawn New page from template and save as index.html for your home page.  Repeat for other site pages.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

Maybe you are looking for

  • Xorg 1.8 upgrade and no keyboard/mouse [solved]

    Well I took the plunge and did a Suy for the 1st time in 6 months or so today... all went well but I have no keyboard or mouse. I have read all the info on the modular configs and opted to stick with my original xorg.conf. Below are my xorg.conf and

  • Best way to get good resolution when hooking up to a TV?

    I've just recently bought a Macbook Pro 13" from the refurb store, and yesterday acquired a mini DVI to HDMI adapter, in order to hook it up to the TV (32" Samsung full Hd LCD).  It was successful enough, but the on screen view was hideous.  At first

  • Outlook task & Contacts first, last name swap

    Hi, Sorry if this has been raised before. I'm using Windows XP SP2 / Outlook 2003 / Nokia 6275 / Bluetooth. Synching Outlook and phone works successfully except for two small issues: * Completed Tasks in Outlook do not delete from phone even though S

  • ASSIGN COMPONENT x OF STRUCTURE not assigning !

    Hello, the problem is that the component PAKET is not getting assigned to my field symbol (<l_str_applparam> type any) and i don't understand why. The PAKET field is type INT4 and the value is 1111.  The importing structure i_str_applparam is also ty

  • Changing Apple PICT to JPG

    I recently purchased an iMac after using an older iMac for 8 years. That means I have tons of pictures in iPhoto 08 that were saved as Apple PICT. I've searched through the Apple Help and Tutorials to find a way to change the PICT pictures to JPG, bu