는select by order by와 tsql string concat가 order by 절에서 함수와 함께 작동하지 않습니까?
create function dbo.wtfunc(@s varchar(50)) returns varchar(10) begin return left(@s, 2); end
GO
select t.* into #test from (
select 'blah' as s union
select 'foo' union
select 'bar'
) t
select * from #test;
declare @s varchar(100);
set @s = '';
select @s = @s + s from #test order by s;
select @s;
set @s = '';
select @s = @s + s from #test order by dbo.wtfunc(s);
select @s;
/* 2005 only*/
select cast((select s+'' from #test order by dbo.wtfunc(s) for xml path('')) as varchar(100))
drop function dbo.wtfunc;
drop table #test;
내가 MSSQL 2000 년과 2005 년에 그것을 시도하고에 의해 순서대로 함수를 사용하는 경우 모두 문자열을 CONCAT하지 않는 다음 TSQL을 ... 고려하십시오. 2005 년 XML 경로 ('')가 작동합니다. 출력은 ...
bar
blah
foo
barblahfoo
foo --nothing concatenated?
barblahfoo
이 문서화 된 곳을 찾을 수 없습니다. 누군가가 왜 이것이 작동하지 않는지에 대해 밝힐 수 있습니까?
편집 :
실제 실행 계획은 다음과 같습니다. 분명히 정렬 및 계산 스칼라이 전혀 도움이 경우
alt text http://i41.tinypic.com/2d6pht3.jpg alt text http://i41.tinypic.com/w2og48.png
아주 좋은 찾기! – dotjoe