Masking characters in varchar

0

Please login or register to vote for this query.

(click on this box to dismiss)

Drupal Answers Meta

Q&A about the site for Drupal developers and administrators

CREATE TABLE #tab(col VARCHAR(100));

INSERT INTO #tab
VALUES ('Walmart'),('Exxon Mobil'), ('Green Mountain Coffee'),('Apple');

SELECT col, 
masked = case when CHARINDEX(' ', col) > 0 then STUFF(
     STUFF(col, 3, LEN(col)-4, REPLICATE('*',LEN(col)-4)), -- same as above
    CHARINDEX(' ', col), 1, ' ') else col end
FROM #tab;

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results