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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:45:38+00:00 2026-06-12T21:45:38+00:00

I have a function that I need to create that reads in the value

  • 0

I have a function that I need to create that reads in the value of a column in a table and output a text value into a new column in the same table. The column in question (confidence_score) will have either a numeric value, a letter, or null value.

If confidence_score(nvarchar(2)) is a number and is less than or equal to 14, I need the computed column to have ‘High’ in it, otherwise ‘Low’. If confidence_score is not a number and has a value of ‘H’, I need the computed column to have ‘High’ in it, otherwise ‘Low’.

Here is the code I am using:

CREATE FUNCTION dbo.avm_confidence_level(@score nvarchar)
RETURNS nvarchar(5) as
BEGIN
DECLARE @conversion as nvarchar(5)
    IF isnumeric(@score) = 1 BEGIN
        IF cast(@score as int) <= 14 BEGIN
            Set @conversion = 'High'
        END
        ELSE BEGIN
            Set @conversion = 'Low'
        END
    END
    ELSE BEGIN
        IF @score = 'H' BEGIN
            Set @conversion = 'High'
        END
        ELSE BEGIN
            Set @conversion = 'Low'
        END
    END

    RETURN @conversion
END

I am getting results using this code that are half right. The first check (isnumeric) seems to be working fine. I am getting High and Low values where I’m expecting them when the value is not a number. The issue seems to be within the isnumeric being true section. I am getting a value of ‘High’ regardless of what numeric value is actually in the confidence_score column. I’m not sure what I’m doing wrong here.

I appreciate any help anyone can offer.

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-06-12T21:45:40+00:00Added an answer on June 12, 2026 at 9:45 pm

    It’s because you defined the function parameter as nvarchar instead of nvarchar(2). It’s truncating anything over one character, so all your ints above 9 are becoming 1. Try changing the definition to:

    CREATE FUNCTION dbo.avm_confidence_level(@score nvarchar(2))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that reads a text file containing two lines, it reads
I have a function that i need to call on iframe mousemove(). But i
I have a function that takes an array of objects and I need to
I have a function that returns two values in a list. Both values need
OK, I have a function in C++ that I need to call from JavaScript,
I need help with my C code. I have a function that sets a
I have this jquery function that works, except I need to add something. I
I need to write a little ruby function that does word wrapping. I have
I have a C function int func( int a, int* b) that I need
I have need for a function pointer that takes two arguments and returns a

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.