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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:06:23+00:00 2026-06-14T06:06:23+00:00

I’m trying to return a specific digit for each number in a dataset, I’ve

  • 0

I’m trying to return a specific digit for each number in a dataset, I’ve written an SQL function and now I need to be able to do the calculation in the function for each number in the dataset. Can you please point me in the correct direction? I don’t know if I should create a temp table then join that, if I should just write a vb function within Reporting Services and do that or if I just need to start over.

Here is the function
USE [CUDatabase]
GO

/****** Object:  UserDefinedFunction [dbo].[fn_Check_Digit]    Script Date: 11/13/2012    14:40:59 ******/ SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[fn_Check_Digit]
(
    @unique_NBR VARCHAR(MAX)
)
RETURNS @Values TABLE
(
    check_digit int,
    unique_nbr int
)
AS

  BEGIN

  -- set up working variables
DECLARE @LEN AS INT
DECLARE @INDEX AS INT
DECLARE @CHAR AS VARCHAR(1)
DECLARE @POSITION AS INT
DECLARE @VALUE AS INT
DECLARE @SUBTOTAL AS INT
DECLARE @BASE AS INT
DECLARE @CHECK_DIG AS INT
SET @LEN = LEN(@MEMBER_NBR)
SET @INDEX = 1
SET @POSITION = 0
SET @VALUE = 0
SET @SUBTOTAL = 0
SET @BASE =0
SET @CHECK_DIG = 0

  -- iterate until we have no more characters to work with
  WHILE @index<=@len
BEGIN
    SET @char = SUBSTRING(@unique_NBR,(@len-@POSITION),1)
    select @value = (SELECT scd.dig_mul_value
                    FROM CUDatabase.DBO.sdcCheckDigit SCD
                    WHERE SCD.dig_place = @index)


    set @value = @value * @char
    SET @index = @index + 1
    SET @POSITION = @POSITION + 1
    SET @SUBTOTAL = @VALUE + @SUBTOTAL


END  
SET @BASE = ((@SUBTOTAL/10)+1)*10
    IF @BASE -@SUBTOTAL = 10
        SET @CHECK_DIG = 0  
    ELSE
        SET @CHECK_DIG = @BASE-@SUBTOTAL

INSERT INTO @Values (check_digit, unique_nbr) VALUES (CAST(@CHECK_DIG AS         int),@unique_NBR)

RETURN 

END    


GO

The table that is in the select statement of that function has the following values in it:
dig_place dig_mul_value
1 7
2 3
3 1
4 7
5 3
6 1
7 7
8 3
9 1

Here is the dataset, I need to loop through each unique_nbr and return the check digit.

`SELECT I.D1NAME,
    IA.ADDRESS_ID,
    A.ADDRESS1,
    A.ADDRESS2,
    A.ADDRESS3,
    A.CITY,
    A.STATE,
    A.ZIP_STR,
    TL.COMPANY_NAME,
    TL.COMPANY_DESCRIPTION,
    TL.EFFECTIVE_ENTRY_DATE,
    TL.AMOUNT,
    TL.ACCOUNT_NBR,
    TL.ACCT_DBRN
FROM MEMBERSHIPPARTICIPANT MP 
    JOIN  INDIVIDUAL I ON
        I.INDIVIDUAL_ID = MP.INDIVIDUAL_ID
        AND I.DL_LOAD_DATE = MP.DL_LOAD_DATE
    JOIN INDIVIDUALADDRESS IA ON
        IA.INDIVIDUAL_ID = I.INDIVIDUAL_ID
        AND IA.IS_PRIMARY = 1
        AND IA.DL_LOAD_DATE = I.DL_LOAD_DATE
    JOIN ADDRESS A ON
        A.ADDRESS_ID = IA.ADDRESS_ID
        AND A.DL_LOAD_DATE = IA.DL_LOAD_DATE
    JOIN (SELECT EFT.unique_NBR,
                EFT.ACCOUNT_NBR,
                EFT.ACH_SDC_NBR,
                EFT.COMPANY_NAME,
                EFT.COMPANY_DESCRIPTION,
                EFT.INDIVIDUAL_ID_NBR,
                EFT.INDIVIDUAL_NAME,
                EFT.XPTIMESTAMP,
                EFT.STANDARD_ENTRY_CLASS,
                EFT.ROUTING_NUMBER,
                EFT.ACCT_DBRN,
                EFT.AMOUNT,
                EFT.EFFECTIVE_ENTRY_DATE
            FROM EFTTRANSACTION EFT
            WHERE EFT.ROUTING_NUMBER = 999999999
                AND EFT.STANDARD_ENTRY_CLASS IN ('WEB','TEL')
                AND EFT.EFFECTIVE_ENTRY_DATE >= '11/01/2012') TL
ON T  L.unique_NBR = MP.unique_NBR
WHERE MP.DL_LOAD_DATE = (SELECT MAX(DL_LOAD_DATE) FROM MEMBERSHIPPARTICIPANT)
    AND MP.PARTICIPATION_TYPE = 101
    --AND MP.unique_NBR = 9835
ORDER BY MP.unique_NBR`

Thanks for any help

  • 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-14T06:06:24+00:00Added an answer on June 14, 2026 at 6:06 am

    All you have to do is call the SQL function you have already created, i.e.

    SELECT I.D1NAME,
        IA.ADDRESS_ID,
        A.ADDRESS1,
        A.ADDRESS2,
        A.ADDRESS3,
        A.CITY,
        A.STATE,
        A.ZIP_STR,
        TL.COMPANY_NAME,
        TL.COMPANY_DESCRIPTION,
        TL.EFFECTIVE_ENTRY_DATE,
        TL.AMOUNT,
        TL.ACCOUNT_NBR,
        TL.ACCT_DBRN,
        dbo.fn_Check_Digit(L.unique_NBR) CheckDigit
    FROM .....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.