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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:07:32+00:00 2026-05-15T14:07:32+00:00

I am still really new to SQL functions. I am trying to figure out

  • 0

I am still really new to SQL functions. I am trying to figure out how to use the in a SQL program properly. I am wanting to test scalar UDF’s that I have created to see that the return the data correctly and can return a large quantity of data in order. I am not sure what is wrong with my syntax in the SQL to use the function as this is my first attempt. Can someone steer me in the right direction?

Here is an example.

Function code :

SET ANSI_NULLS_ON
GO
GET QUOTED_IDENTIFIER ON
GO

ALTER FUNCTION dbo.FN_LTV_Ranges

(

   @LTV_RANGE     decimal(4,3)
)

Returns variable (160
as 
Begin

declare @Return     varchar(16)
select  @Return =

        Case 
        When @LTV_Range is NULL then 'Missing'
        When @LTV_Range is 00.00 then 'Missing'
        When @LTV_Range <= 0.75 then '<=0.75'
        When @LTV_Range between 0.75 and 0.80 then '75-80'
        When @LTV_Range between 0.80 and 0.90 then '80-90'
        When @LTV_Range between 0.90 and 1.00 then '90-100'
        When @LTV_Range >= 100 then '100+'
        else null end

        Return &Return
END

here is SQL program to call and test above function:

declare @LTV_Range         decimal(4,3)

Select top 600   s.LNumber

from OPENQUERY (SvrLink,  '

Select Lnumber, dbo.FN_LTV_Range(@LTV_Range)

 from some_table s
        where s.LNumber > '0'
          group by @LTV_Range
          Order by @LTV_Range

for Fetch only with UR')

Here is error returned on attempt to run SQL program:

OLE CB provider “MSDASQL” for linked server “SvrLink” returned message “(IBM)(CLI Driver) (DB2/LINUXX8641) SQL0306N “@LTV_RANGE” is not valid in context where it is used. SQLSTATE=
42703

Msg 7350, Level 16, State 2, Line 5
Cannot get the column information from OLE DB provider “MSDASQL” for linked server “SrvLinnk”

  • 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-15T14:07:33+00:00Added an answer on May 15, 2026 at 2:07 pm

    Well, the function should read like this at least if it’s for SQL Server: what you have above is wrong

    ALTER FUNCTION dbo.FN_LTV_Ranges
    (
    
       @LTV_RANGE     decimal(4,3)
    )
    Returns varchar(16)
    as 
    Begin
    declare @Return     varchar(16)
    select  @Return =
            Case 
            When @LTV_Range is NULL then 'Missing'
            When @LTV_Range = 0 then 'Missing'
            When @LTV_Range <= 0.75 then '<=0.75'
            When @LTV_Range between 0.75 and 0.80 then '75-80'
            When @LTV_Range between 0.80 and 0.90 then '80-90'
            When @LTV_Range between 0.90 and 1.00 then '90-100'
            When @LTV_Range >= 100 then '100+'
            else null end
            Return @Return
    END
    

    For decimal(4,3) your min/max is +/- 9.999 so why this “When @LTV_Range >= 100 then '100+'“?

    Next, why have OPENQUERY submitting a SQL call to a DB2 instance that includes a SQL Server function?

    I assume you want the function call + grouping + ordering outside. And where do you set @LTV_Range?

    Finally, grouping + ordering on @LTV_Range is pointless: it’s a single value so I assume you mean to group/order on the result of the function call

    declare @LTV_Range decimal(4,3)
    Select top 600
       s.LNumber, dbo.FN_LTV_Range(@LTV_Range)
    from
         OPENQUERY (SvrLink,  '
    Select Lnumber
     from some_table s
            where s.LNumber > '0'
    for Fetch only with UR')
    group by dbo.FN_LTV_Range(@LTV_Range)
    Order by dbo.FN_LTV_Range(@LTV_Range)
    

    The question as it stands makes no sense I’m sorry to say…

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

Sidebar

Related Questions

I recently switched over to a MacBook Pro so I'm still really new at
I'm really new to .NET, and I still didn't get the hang about how
still trying to find where i would use the yield keyword in a real
I'm new with javascript, so i'm trying to use two jQuery plugins, together they
I've tried using source control for a couple projects but still don't really understand
still new to the world of linq, and i need some help flatening a
Still new to Objective C, and I'm having some trouble that I just can't
I still very new using Subversion. Is it possible to have a working copy
I am looking to build a new website which will require a sql server
I'm running into a problem when trying to select records from my 2005 MS-SQL

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.