Skip to content
Loading
  • Nitin Sontakke
    0
    You didn't answer my first question.
     
    Is 'A' and 'a' both have value 1 or different? If different then what?
    0
  • Nanddeep Nachan
    0
    I guess, case insensitive calculation of alphabet to numbers 
    0
  • Sai Reddy
    0
    Example
    I have passed string through parameter like='abcde' 
    then it has to count alphabitical values for the string like 1+2+3+4+5=15
    final result should be 1+5=6 
     
    I have created a table
     
    ID  Alpha
    1    A
    2    B
    3     C
    4     D
    ...    .... 
    0
  • Sai Reddy
    0
    Hi Nitin Sontakke
     
    Yes, Both A and a are having same value 1
    B and b=2
    C and c=3
    ..
    Z and z=4 
    0
  • Sai Reddy
    0
    Can any one please help me?
    The procedure can be in mysql or tsql no problem. 
    0
  • Sai Reddy
    0
    Thank you Nitin, how can we do the same in mysql as i am working on mysql.
    0
  • Nitin Sontakke
    0
    Unfortunately, I am not quite conversant with language used in MySql. Sorry!
     
    You will probably have to work that out. If you are learning, this should be a pretty easy exercise, as the code is very basic.
     
    Find out all equivalent functions for len, str, ascii, substring, etc.
    0
  • Packiaraj Santhiyagu
    0

    Hi Sai

    I work out and bring the result. It will work sure.

    I create this SP in MSSQL server. So, run in MSSQL server

    If you need any clarification, please comment immediately.

    I command everything for your understanding.

     
    1. CREATE PROC calstringValue(  
    2. @passedString varchar(100)  
    3. )  
    4. AS  
    5. BEGIN  
    6.     --Declaration  part  
    7.     declare @index int  
    8.     declare @len int  
    9.     declare @char char(1)  
    10.     declare @total int  
    11.     declare @charvalue int  
    12.   
    13.     -- value setting part  
    14.     set @index = 1 --by default set index=1  
    15.     set @len= LEN(@passedString)  
    16.     set @total=0;  
    17.     set @charvalue=0;  
    18.   
    19.     -- Looping here  
    20.     WHILE @index<= @len  
    21.     BEGIN  
    22.         set @char = SUBSTRING(@passedString, @index, 1) -- it will pick current index charater  
    23.         set @char=lower(@char) -- convert character as lower case  
    24.         set @charvalue=ASCII(@char)-96 -- ASCII value start from 97 for 'a' so i minus 96  
    25.         set @total+=@charvalue -- here sum the value  
    26.           
    27.         SET @index= @index+ 1 -- increment the loop value  
    28.     END  
    29.     SELECT @total -- print the result  
    30. END  
    execute the SP using below command
    1. EXEC calstringValue @passedString='PACKIA'  
     
    0
  • Nitin Sontakke
    0
    @Sai, are you 100% sure that the accepted answer is giving you an expected output? If yes, then may be your question is not been put correctly.
     
    Please confirm.
    0