Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8408221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:34:26+00:00 2026-06-09T23:34:26+00:00

I am getting some strange behaviour from SQL Server. I have an underlying view

  • 0

I am getting some strange behaviour from SQL Server. I have an underlying view that returns an amount field. That amount field is casting from VARCHAR(50) to FLOAT.

I can successfully run the following query:

SELECT AMOUNT
FROM vReturnDetails

I can also successfully run the following query:

SELECT AMOUNT
FROM vReturnDetails v 
    INNER JOIN MyTable t 
        ON t.LicenceNumber = v.LicenceNumber
        AND t.ReturnYear = v.ReturnYear 
WHERE t.ReturnYear = 2012

Similarly I can run this query:

SELECT AMOUNT
FROM vReturnDetails v 
    INNER JOIN MyTable t 
        ON t.LicenceNumber = v.LicenceNumber
        AND t.ReturnYear = v.ReturnYear 
WHERE t.ReturnYear <> 2012

This is where it gets strange though, I cannot run either of the following:

SELECT AMOUNT
FROM vReturnDetails v 
    INNER JOIN MyTable t 
        ON t.LicenceNumber = v.LicenceNumber
        AND t.ReturnYear = v.ReturnYear 
WHERE t.ReturnYear = 2012 OR t.ReturnYear <> 2012

SELECT AMOUNT
FROM vReturnDetails v 
    INNER JOIN MyTable t 
        ON t.LicenceNumber = v.LicenceNumber
        AND t.ReturnYear = v.ReturnYear 

I can successfully run this query though:

SELECT AMOUNT
FROM vReturnDetails v 
    INNER JOIN MyTable t 
        ON t.LicenceNumber = v.LicenceNumber
        AND t.ReturnYear = v.ReturnYear 
WHERE t.ReturnYear <> 2013 --2013 is a dummy value that doesn't exist

Can anyone shed any light on what is happening under the covers here. It makes no sense at all to me so I’m not sure where to start looking to fix the problem.

The error I am receiving is

Error converting data type varchar to float.

This is on Sql Server 2008 SP2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:34:27+00:00Added an answer on June 9, 2026 at 11:34 pm

    SQL Server is complicated. The order of processing in the SQL engine is not necessarily the same as the order in the query. Filters in WHERE clauses, for instance, can be applied when the data is read, or later after the data is processed.

    Clearly, you have some values in the AMOUNT field that are not valid floats. The simplest explanation is that when you ran:

    SELECT AMOUNT
    FROM vReturnDetails
    

    You did not return all the rows . . . and the row with the bad data was later.

    Alternatively, vReturnDetails is a view based on underlying data, some of which is bad. When the query is compiled, it might affect where the filtering occurs. In some cases, the engine might decide to read all the data, do the conversion, and then continue — but it gets an error in the conversion disrupting the process.

    You can fix this by changing the view to something like:

    select (case when isnumeric(amountstr) = 1 then cast(amountstr as float) end) as Amount
    

    SQL Server does guarantee the order of evaluation in a case statement. So, this should not return an error.

    ISNUMERIC() and CONVERT to FLOAT are not fully consistent. I know ISNUMERIC accepts commas and dollar signs (and maybe other characters). You can also try this (assuming you are using US-style formats for numbers):

    select (case when isnumeric(amountstr) = 1
                 then cast(replace(replace(amountstr, ',', ''), '$', '') as float) end) as Amount
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have fancybox installed on my website and I am getting some strange behaviour.
I'm getting some strange hover behaviour from IE9 which seems to be resulting from
I am getting some strange behavior involving database queries that I have never seen
I'm getting some strange behaviour from EF Code First when I add an object
I am getting some strange behavior from list view. I need to change background
I'm getting some strange behaviour with my form (using Zend Form). I have a
I'm getting some strange behavior from a listview/the getChildAt method. I have a HashSet,
I'm getting some very strange behaviour using the following switch statement: string recognise_mti(int mti_code)
I'm trying to learn python and have encountered some strange behaviour. I am experimenting
I have some strange behavior occurring in an ASP.NET application that I am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.