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 9175249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:52:57+00:00 2026-06-17T16:52:57+00:00

I have a varchar field that should always contain a numeric (decimal) value when

  • 0

I have a varchar field that should always contain a numeric (decimal) value when a filter is applied. But I get “Error converting data type varchar to numeric” when i run sql like this:

SELECT CAST(A.text AS numeric(38,16)) 
FROM Answers A
INNER JOIN Questions Q ON Q.ID = A.QuestionID
WHERE Q.Text = 'Rating'
AND isnumeric(A.text) = 1

There is only one value that passes the isnumeric test but fails the cast:

DECLARE @text varchar(100)
SET @text = '2.83417869359255E-02'
SELECT CASE WHEN ISNUMERIC(@text) = 1 THEN CAST(@text AS NUMERIC(38,16)) ELSE NULL END

How should I ensure that values like this are handled? At the end of the day I want to count all values that are less than 5, so numbers like ‘2.83417869359255E-02’ could be rounded to zero. I have also run a query to examine the values in the table together with the length of the varchar with these results:

MaxValue             MinValue             LenVarChar
-------------------- -------------------- -----------
0                    0                    1
10                   10                   2
2.2                  9.2                  3
3.55                 6.32                 4
5.453125             5.453125             8
2.79989361763        9.47216796875        13
2.089115858078       9.132080078125       14
1.1529632806778      9.8538990020752      15
0.64174896478653     9.83681106567383     16
0.111961431801319    0.991760730743408    17
2.83417869359255E-02 2.83417869359255E-02 20
  • 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-17T16:52:57+00:00Added an answer on June 17, 2026 at 4:52 pm

    Not storing numbers as strings would be my preferred solution but you could always check for D or E and then cast to float first.

    DECLARE @text VARCHAR(100)
    
    SET @text = '2.83417869359255E-02'
    
    SELECT
        CASE
        WHEN ISNUMERIC(@text) = 1
        THEN      CASE 
                  WHEN @text LIKE '%[DE]%' 
                  THEN CAST(CAST(@text AS FLOAT) AS NUMERIC(38, 16))
                  ELSE @text
                  END 
        END 
    

    There are still potentially problematic inputs however such as $ (which passes the ISNUMERIC test but would require a cast to money)

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

Sidebar

Related Questions

I have the field receiptno , which is a varchar holding a numeric value,
I have a varchar field that looks like (sadly I have no control over
I have an SQL Server 2005 table that has a varchar(250) field which contains
I have a field COLORS (varchar(50)) in a my table SHIRTS that contains a
I have a field in my table that is a varchar and contains alphabetic,
I have a varchar field in my database which i use for two significantly
I have one field in Database ( Sql Server DB 2000) with varchar field
I have a field type varchar in sql server. It contains data like 010109
In my database I have changed the type of a field from VARCHAR to
Ok I'm using SQL Server 2008 and have a table field of type VARCHAR(MAX)

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.