How to resolve the algorithm Middle three digits step by step in the SQL programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Middle three digits step by step in the SQL programming language
Table of Contents
Problem Statement
Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values; the first line should return valid answers, those of the second line should return clear indications of an error: Show your output on this page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Middle three digits step by step in the SQL programming language
Source code in the sql programming language
;WITH DATA
AS (SELECT CAST(ABS(NUMBER) AS NVARCHAR(MAX)) charNum,
NUMBER,
LEN(CAST(ABS(NUMBER) AS NVARCHAR(MAX))) LcharNum
FROM TABLE1)
SELECT CASE
WHEN ( LCHARNUM >= 3
AND LCHARNUM % 2 = 1 ) THEN SUBSTRING(CHARNUM, LCHARNUM / 2, 3)
ELSE 'Error!'
END Output,
NUMBER Input
FROM DATA
You may also check:How to resolve the algorithm Van der Corput sequence step by step in the REXX programming language
You may also check:How to resolve the algorithm Multifactorial step by step in the Julia programming language
You may also check:How to resolve the algorithm Safe primes and unsafe primes step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Random numbers step by step in the Eiffel programming language
You may also check:How to resolve the algorithm Happy numbers step by step in the Euphoria programming language