How to Get the Required Output

  • 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

  • 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

  • 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

  • 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