This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Check the below input string and expected output for counting the total Lowercase, Uppercase and Other Characters (Including SPACE) in the given string.
Input String:
1 |
'I am Anvesh Patel, owner @str DBRND.COM' |
Expected Output:
1 2 3 |
UpperCase_Count LowerCase_Count OtherCharacter_Count --------------- --------------- -------------------- 11 19 9 |
Solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
DECLARE @str AS VARCHAR(100) = 'I am Anvesh Patel, owner @str DBRND.COM' SELECT SUM(CASE WHEN ASCII(string) BETWEEN 65 AND 90 THEN 1 ELSE 0 END) as UpperCase_Count ,SUM(CASE WHEN ASCII(string) BETWEEN 97 AND 122 THEN 1 ELSE 0 END) as LowerCase_Count ,SUM(CASE WHEN (( ASCII(string) NOT BETWEEN 97 AND 122 ) AND ( ASCII(string) NOT BETWEEN 65 AND 90 )) THEN 1 ELSE 0 END) as OtherCharacter_Count FROM ( SELECT DISTINCT Number ,SUBSTRING(@str,Number,1) as string FROM Master..spt_Values WHERE Number > 0 and number <= LEN(@str) )as t |
Please try the different solution for this puzzle and share it via comment...