Click here to Skip to main content
15,886,099 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Now imagine you a table with all the alphabets from A to Z(not case sensitive) having values from 1 to 26. Now what I want you to do is write a T-SQL (if possible without using cursor) to calculate the value of the “Name” by adding the value of its characters.

Example:
For Nobel the value would be: (N)14 +(O)15+(B)2+(L)12+(E)5 = 48
The characters are not case sensitive, so “Noble” = “noble”
Posted
Comments
[no name] 23-Jul-12 9:19am    
"Now what I want you to do is write a T-SQL"... Okay I will get started on this right away. 2 questions first. How much are you paying and when can I expect payment?

SQL
DECLARE @NameString VARCHAR(100)

SELECT @NameString='Abv'
SELECT @NameString=UPPER('Abv')

SELECT SUM(ASCII(SUBSTRING(@NameString,Number,1))-64) 'Sum_Of_Charater'
FROM MASTER.dbo.spt_values 
WHERE Number BETWEEN 1 AND LEN(@NameString) AND type='P'


-- Check this Solution
 
Share this answer
 
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900