Click here to Skip to main content
15,896,398 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friend
i store a value RAMESH SHARMA in data base.i want to take this RAMAESH SHARMA like
R.SHARMA so how can i do this with sql query.

thanks
Posted

You could use
SQL
SELECT SUBSTRING(Name,1,1) + '. ' +
     SUBSTRING(Name, CHARINDEX(' ', Name) + 1, LEN(Name) - CHARINDEX(' ', Name))

You may run into problems with middle names.
At our site we store the name on the database in it's component parts i.e. firstName, MiddleNames, lastName which would make this task easier

Ok - have also just found the following links ..
http://www.sql-server-helper.com/tips/split-name.aspx[^] which expands on my solution above
and
http://www.sqlservercentral.com/Forums/Topic943562-338-1.aspx#bm944589[^]
 
Share this answer
 
v2
Hey you could do a simple statement like
SQL
SELECT RIGHT(Name,2) + '. ' +
    LEFT(Name,LEN(Name) - CHARINDEX(' ', Name))
 
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