begin
set @tmp = substring(@tmp, charindex(‘as’, @tmp)+2, len(@tmp))
end
else
begin
if (charindex(‘ ‘, @tmp) > 0)–别名的第二种写法,带空格(” “)的格式
begin
while(charindex(‘ ‘, @tmp) > 0)
begin
set @tmp = substring(@tmp, charindex(‘ ‘, @tmp)+1, len(@tmp))
end
end
end
end
set @TotalFields = @TotalFields + @tmp
end
if (@i=0)
set @Fields = ”
else
set @Fields = substring(@Fields, @i+1, len(@Fields))
end
–print @TotalFields
set @SQL2 = @SQL2 + ‘ select ‘ + @TotalFields + ‘ from #tb where PK between @PKBegin and @PKEnd order by PK’ –输出最终显示结果










