May 24, 2012 at 5:13 am
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
May 24, 2012 at 5:18 am
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;
May 24, 2012 at 5:27 am
select STUFF(s,4,len(s)-3,replicate('*',len(s)-3))
from
(
select 'Lokesh' s
union select 'Gowda' s
) q
May 24, 2012 at 5:38 am
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