这个需要自定义函数,我写了一个,可以参考
ALTER FUNCTION [dbo].[fun_getstrEvery4]
(@str VARCHAR(500))
RETURNS VARCHAR(500)
AS
BEGIN
declare @len int,
@loopnum int=1,
@returnstr VARCHAR(500)=''
if len(@str) % 4 =0
begin
set @len=len(@str)/4 -1
end else
begin
set @len=len(@str)/4
end
while @loopnum<=@len
begin
set @returnstr=@returnstr+','+SUBSTRING(@str,@loopnum*4 + 1,4)
set @loopnum=@loopnum+1
end
RETURN left(@str,4)+@returnstr
END