alter
Function quas(@sql nvarchar(1000))
returns varchar(300)
as
begin
declare @i int
declare @j int
set @sql=SUBSTRING(@sql,1,charindex('from',@sql)-1)
declare @ss as nvarchar(100)
set @ss=''
declare @del as nvarchar(100)
set @del=''
select @i=charindex(',',@sql)
select @j=charindex('as',@sql)
declare @count int
set @count=5
while isnull(@i,0)>0
and isnull(@j,0)>0 and @count>0
begin
if @i<@j
begin
set @ss=@ss+substring(@sql,1,charindex('as',@sql)-1)+','
set @sql=REPLACE(@sql,substring(@sql,1,charindex('as',@sql)-1),'')
end
if @i>@j
begin
set @del=SUBSTRING(@sql,@j,@i-1)
set @sql=REPLACE(@sql,@del,'')
end
set @count=@count-1
set @del=''
select @i=charindex(',',@sql)
select @j=charindex('as',@sql)
end
declare @k int
select @k=charindex('as',@sql)
if isnull(@k,0)>0
begin
set @ss=@ss+SUBSTRING(@sql,1,@k-1)
end
else
begin
set @ss=@ss+@sql
end
select @ss=replace(@ss,',,',',')
--select @ss
return @ss
end
[
本帖最后由 huwengui 于 2012-12-8 20:02 编辑 ]