风过的影子

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 

/*
转化字段格式
declare @PointInfo nvarchar(100)
set @PointInfo = ',PointType,Rank,'
select dbo.GetPointField(@PointInfo)
*/
Create function GetPointField
(
    
@PointInfo nvarchar(100)
)
returns nvarchar(2000)
as
begin
declare @PointInfos nvarchar(2000)
set @PointInfos= ''
set @PointInfo=','+@PointInfo+','
declare @point nvarchar(200)
declare @start int
declare @last int
set @start=1
set @last=charindex(',',@PointInfo,@start+1)
while @last>0
begin
    
set @point=substring(@PointInfo,@start+1,@last-@start-1)
    
if @point<>',' and @point<>''
    
begin
        
set @point='cast('+@point+' as nvarchar(50))'
        
set @PointInfos=@PointInfos+','+@point
    
end
    
set @start=@last
    
set @last=charindex(',',@PointInfo,@start+1)
end
set @PointInfos=substring(@PointInfos,2,len(@PointInfos)-1)
return @PointInfos
end

 

执行语句

declare @PointInfo nvarchar(100)
set @PointInfo = ',PointType,Rank,'
select dbo.GetPointField(@PointInfo)

执行结果

cast(PointType as nvarchar(50)),cast(Rank as nvarchar(50))

 

 

posted on 2009-06-19 10:31  风过的影子  阅读(501)  评论(1编辑  收藏  举报