要返回多个值,需要声明一个表值函数。
part of the query
.
create function [dbo].[fn_AlphaNumreicSort] (@AlphaNumreicValue nvarchar(MAX))
returns table
as
return (
select
LEFT(@AlphaNumreicValue, PATINDEX('%[0-9]%', @AlphaNumreicValue) - 1) as SortedVar1,
CONVERT(INT, SUBSTRING(@AlphaNumreicValue, PATINDEX('%[0-9]%', @AlphaNumreicValue), LEN(@AlphaNumreicValue))) as SortedVar2
);
然后在查询中使用它
outer apply
select ...
from
some_table
outer apply [dbo].[fn_AlphaNumreicSort](InvoiceID) as sort_values
...
order by
sort_values.SortVar1,
sort_values.SortVar2