alter function GetStr( @num bigint)
 returns  varchar(1000) 
 as 
begin   
declare @str varchar(100)
SELECT @STR=''
declare @str_RESULT varchar(100)
SELECT @str_RESULT=''
declare @index int 
select  @index=len(@num)
declare @num_left varchar(100)
declare @num_right varchar(100)
while(@index>3)
begin 
select @num_left=left(@num,3)
select @num_right=RIGHT(@num,len(@num)-3)
select @num_left=@num_left+'.'
select @str=@str_RESULT+@num_left
SELECT @str_RESULT=@str_RESULT+@num_left
select @index=len(@num_right)
select @num=@num_right
if(@index>3)
BEGIN
continue
END 
else
BEGIN 
SELECT  @str=@str+@num_right
break
END
end
RETURN @str
end select  [dbo].GetStr(12345670980002)
/*
   123.456.709.800.02
/*

解决方案 »

  1.   

    抛给你一块砖:
    select rtrim(no)+'.'
    from (
            select rn,substring(no,rn*3-2,3) as no
            from (select N'12345455666767' as no) a
            left join (select (select count(*) 
                                   from sysobjects 
                                   where id>=b.id
                                   ) as rn 
                          from sysobjects b
                        ) c on ceiling(len(a.no)/3.0)>=c.rn
             ) d
    order by rn
    for xml path('')-- for sql server 2005