July 20, 2011 at 4:18 am
Hi Friends,
I have a table consists of A Column which comprises of following values
'sachin Tendulkar'
'kapil Dev'
'venkatesh prasad'
'shoiab akthar'
'ravi shastri'
The Output should be a computed column having the following values
ST
KD
VP
SA
RS
Please help me out how do i make it..
Let me know ASAP. Waiting for your Reply.
Thanks In Advance,
Sandeep IVS
July 20, 2011 at 5:18 am
Try this for size...
USE [SandBox]
GO
IF OBJECT_ID('tempdb.dbo.#TESTNames') IS NOT NULL
DROP TABLE #TESTNames
CREATE TABLE #TESTNames (
name VARCHAR(100) NULL,
initials AS (UPPER(LEFT([name],(1))+SUBSTRING([name],CHARINDEX(' ',[name],(1))+(1),(1))))
)
INSERT #TESTNames(name)
VALUES ('sachin Tendulkar'),('kapil Dev'),('venkatesh prasad'),('shoiab akthar'),('ravi shastri')
SELECT * FROM #TESTNames
Tim
July 20, 2011 at 5:22 am
You possibly want to add a REPLACE in there as well to deal with possibility of double spaces.
initials AS (UPPER(LEFT([name],(1))+SUBSTRING(REPLACE([name],' ',' '),CHARINDEX(' ',[name],(1))+(1),(1))))
Cheers
Tim
July 20, 2011 at 5:37 am
Thanks A Lot Tim 🙂
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply