String Manipulation - Please help

  • Hi, I need to manipulate string as below.

    Example :

    set @str1 = 'Lokesh'

    set @str2 = 'Gowda'

    Result Should be:

    @str1 = Lok***

    @str2 = Gow**

    Please assist without using any loops. Thanks

  • DECLARE @str1 CHAR(6) = 'Lokesh', @str2 CHAR(5) = 'Gowda';

    --View current values

    SELECT @str1, @str2;

    --Update the variables

    SET @str1 = LEFT(@str1,3)+REPLICATE('*',LEN(@str1)-3);

    SET @str2 = LEFT(@str2,3)+REPLICATE('*',LEN(@str2)-3);

    --View new values

    SELECT @str1, @str2;


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • select STUFF(s,4,len(s)-3,replicate('*',len(s)-3))

    from

    (

    select 'Lokesh' s

    union select 'Gowda' s

    ) q

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • declare @str1 varchar(10),

    @str2 varchar(10)

    set @str1 = 'Lokesh'

    set @str2 = 'Gowda'

    select left(@str1,3)+replicate('*',len(@str1)-3), left(@str2,3)+replicate('*',len(@str2)-3)

    ***The first step is always the hardest *******

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply