The easiest way to do that is using a function
CREATE FUNCTION [dbo].[HideNameWithAsterisks](@Name varchar(max))
RETURNS varchar(MAX)
AS
BEGIN
DECLARE @loop int = LEN(@Name)
WHILE @loop > 1
SELECT @Name = STUFF(@Name, @loop, 1,
CASE WHEN SUBSTRING(@Name, @loop - 1, 2) like '% ' THEN ' '
WHEN SUBSTRING(@Name, @loop - 1, 2) like ' %' then substring(@Name, @loop, 1)
ELSE '*' END), @loop += -1
return @Name;
END
and here is the usage
SELECT dbo.HideNameWithAsterisks(N'The KinGS Never DIE!') Output: T** K**** N**** D***
