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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:52:44+00:00 2026-05-13T20:52:44+00:00

I’m working on a query with a varchar column called ALCOHOL_OZ_PER_WK . Part of

  • 0

I’m working on a query with a varchar column called ALCOHOL_OZ_PER_WK. Part of the query includes:

where e.ALCOHOL_OZ_PER_WK >= 14

and get the errors:

Arithmetic overflow error converting varchar to data type numeric.

and:
Error converting data type varchar to numeric.

Looking into the values actually stored in the column, the largest look close to 100, but some of the entries are ranges:

9 - 12
1.5 - 2.5

I’d like to get the upper limit (or maybe the midpoint of the range) from rows with entries like this and have it be the value being compared to 14.

What would be the (or an) easy way to do this?

As always, thank you!

  • 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-13T20:52:45+00:00Added an answer on May 13, 2026 at 8:52 pm

    Your DB is obviously result of some survey, and it seems to contain the original survey data. The usual way is to run this through an ECCD (Extract, Clean, Conform, Deliver) process and store clean and standardized data into a separate database (maybe a warehouse) which can then be used for analytics and reporting.

    If you have SSIS use data profiling task to get an idea of types of strings you have in there. The Column Pattern Profile reports a set of regular expressions on the string column, so you will get an idea of what’s inside those strings. If you do not have SSIS, you can use eobjects DataCleaner to do the same.

    If you can not spare a new database or at least a new table — at minimum add a numeric column to this table and then extract numeric values form those strings into the new column. You may want to use “something else” (SSIS, Pentaho Kettle, Python, VB, C#) to do this — in general T-SQL in not very good at string processing.

    My guess is that this is not the only column that has garbage inside, so any analysis that you may run on this may be worthless.

    And if you still think that the ranges are the only problem, this example may help:

    First some data

    DECLARE @myTable TABLE ( 
      AlUnits varchar(10)
      ) ;
    
    INSERT  INTO @myTable
            (AlUnits )
    VALUES  ( '10' )
    ,       ( '15' )
    ,       ( '20' )
    ,       ( '7 - 12' )
    ,       ( '3 - 5' )
    ;
    

    The query splits records into two groups, numeric and not numeric — assumed ranges.

    ;
    WITH  is_num
            AS ( SELECT CAST(AlUnits AS decimal(6, 2)) AS Units_LO
                       ,CAST(AlUnits AS decimal(6, 2)) AS Units_HI
                 FROM   @myTable
                 WHERE  ISNUMERIC(AlUnits) = 1
               ),
          is_not_num
            AS ( SELECT CAST( RTRIM(LTRIM(LEFT(AlUnits,
                              CHARINDEX('-', AlUnits) - 1)))
                            AS decimal(6,2)) AS Units_LO
                       ,CAST(RTRIM(LTRIM(RIGHT(AlUnits,
                                   LEN(AlUnits)
                                   - CHARINDEX('-', AlUnits))))
                            AS decimal(6,2)) AS Units_HI
                 FROM   @myTable
                 WHERE  ISNUMERIC(AlUnits) = 0
               )
      SELECT  Units_LO
             ,Units_HI
             ,CAST(( Units_LO + Units_HI ) / 2.0 AS decimal(6, 2)) AS Units_Avg
      FROM    is_num
      UNION ALL
      SELECT  Units_LO
             ,Units_HI
             ,CAST(( Units_LO + Units_HI ) / 2.0 AS decimal(6, 2)) AS Units_Avg
      FROM    is_not_num ;
    

    Returns:

    Units_LO    Units_HI    Units_Avg 
    ----------- ----------- ----------
    10.00       10.00       10.00     
    15.00       15.00       15.00     
    20.00       20.00       20.00     
    7.00        12.00       9.50      
    3.00        5.00        4.00      
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

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.