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

  • SEARCH
  • Home
  • 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 703557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:50:39+00:00 2026-05-14T03:50:39+00:00

I am trying to select rows from a table where one of the (NVARCHAR)

  • 0

I am trying to select rows from a table where one of the (NVARCHAR) columns is within a numeric range.

SELECT ID, Value
FROM Data
WHERE ISNUMERIC(Value) = 1 AND CONVERT(FLOAT, Value) < 66.6

Unfortunately as part of the SQL spec the AND clauses don’t have to short circuit (and don’t on MSSQL Server EE 2008). More info: Is the SQL WHERE clause short-circuit evaluated?

My next attempt was to try this to see if I could achieve delayed evaluation of the CONVERT

SELECT ID, Value
FROM Data
WHERE (CASE WHEN ISNUMERIC(Value) = 1 THEN CONVERT(FLOAT, Value) < 66.6 ELSE 0 END)

but I cannot seem to use a < (or any comparison) with the result of a CONVERT. It fails with the error

Incorrect syntax near '<'.

I can get away with

SELECT ID, CONVERT(FLOAT, Value) AS Value
FROM Data
WHERE ISNUMERIC(Value) = 1

So the obvious solution is to wrap the whole select statement in another SELECT and WHERE and return the converted values from the inner select and filter in there where of the outer select. Unfortunately this is where my Linq-to-sql problem comes in. I am filtering not only by one range but potentialy by many, or just by the existance of the record (there are some date range selects and comparisons I’ve left out.)

Essentially I would like to be able to generate something like this:

SELECT ID, TypeID, Value
FROM Data
WHERE (TypeID = 4 AND ISNUMERIC(Value) AND CONVERT(Float, Value) < 66.6) 
      OR (TypeID = 8 AND ISNUMERIC(Value) AND CONVERT(Float, Value) > 99)
      OR (TypeID = 9)

(With some other clauses in each of those where options.) This clearly doesn’t work if I filter out the non-ISNUMERIC values in an inner select.

As I mentioned I am using Linq-to-sql (and PredicateBulider) to build up these queries but unfortunately

Datas.Where(x => ISNUMERIC(x.Value) ? Convert.ToDouble(x.Value) < 66.6 : false)

Gets converted to this which fails the initial problem.

WHERE (ISNUMERIC([t0].[Value]) = 1) AND ((CONVERT(Float,[t0].[Value])) < @p0)

My last resort will have to be to outer join against a double select on the same table for each of the comparisons but this isn’t really an idea solution. I was wondering if anyone has run into similar issues before?

  • 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-05-14T03:50:40+00:00Added an answer on May 14, 2026 at 3:50 am

    I dont think the issue is the AND itself, but rather the convertion from NVARCHAR to FLOAT

    Have a look at the following example

    DECLARE @Table TABLE(
            Value NVARCHAR(10)
    )
    
    INSERT INTO @Table SELECT '1'
    INSERT INTO @Table SELECT '100'
    INSERT INTO @Table SELECT 'A'
    
    SELECT  *
    FROM    @Table
    WHERE   ISNUMERIC(Value)= 1 AND CAST(CAST(Value AS VARCHAR(10)) AS FLOAT) > 50
    
    SELECT  *
    FROM    @Table
    WHERE   ISNUMERIC(Value)= 1 AND CAST(Value AS FLOAT) > 50
    

    The last select is where I get the error stating

    Msg 8114, Level 16, State 5, Line 13
    Error converting data type nvarchar to
    float.

    But the first select works fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, I was trying to select rows from one table if there are no
I'm trying to select rows from a table, one row per email address, and
So I am trying to insert multiples rows of data from one table to
i am trying to pull data from one table, compare columns to a variable,
I'm trying to do a query to filter on rows from one table and
I am trying to get 2 rows from a table at one shot. The
I'm trying to use a SELECT statement and fetch all rows from a table
Im trying to move data from one table to another because the needs of
I am trying to run a code to insert rows from one table using
I am trying to combine rows from one table with my query in MS

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.