Is there any particular reason why adding an additional join to an ordered table would reorder the result set?
Using a left join on the existing result set
table-valued function is similar to below (function returns @table):
conditional
BEGIN
INSERT @table
(col1)
select col1 from table1
order by col1, x, y
END
ELSE
BEGIN
INSERT @table
(col1)
select col1 from table1
order by col1, x, y, z
END