1.添加函数 rpad
--从右边填充字符串
ALTER FUNCTION [dbo].[rpad]
(
-- Add the parameters for the function here
@str nvarchar(100),@len INT,@fix NVARCHAR(1)
)
RETURNS nvarchar(100)
AS
BEGIN
-- Declare the return variable here
DECLARE @res nvarchar(100)
-- Add the T-SQL statements to compute the return value here
SELECT @res = @str+replicate(@fix,@len-len(@str))
-- Return the result of the function
RETURN @res
END
2.编写sql
UPDATE 表名
SET 字段名 = SUBSTRING (
dbo.rpad(
SUBSTRING (字段名, 1, 1),
LEN (字段名) * 2,
'*'
),
1,
LEN (字段名)
)
WHERE
字段名 IS NOT NULL;