PRB: ???? ????? "?" ????? ????????? ????? ????? ????? ??? ???? ?????

?????? ????????? ?????? ?????????
???? ???????: 287515 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

???????

?? ????? ????? ??? ?????? ??? ????? ?? ????? ????? ?? ????????? ORDER BY ????????? ????? ?????. ????? ????? ????????? ????? ????? ?? Microsoft SQL Server ??? ?? ?? ??? ????? ??????? SQL ???????? ??? ??????? ?? ???? ORDER ?????????. ?????? ??? ???? ?? ????????? ?? ???? ???? ??????? ????? ????? ????? ???? ???? ????? "???? ?? ?????????" ?? ??? ???????.

?????

???? ?????? ??????? ????? ????? ??? ????.

??? examination ????? SHOWPLAN ????????? ???? ??????? ??????? SQL Server ??? ????? ?????? ??? ??????? ????? ??? ??????? ?? ????????? ORDER BY ? ?? ????? ??? ????? ??? ????????? ??? ??? ??????? ?? ????? SELECT ?? ?????????. ???? ???? ?? ??????? ?????? ????? ????????? ????? ????? ??? ??????? ????????.

????? ??????? ANSI SQL-92 ?? ???? ?????? ???? ?????? ???? ORDER BY ?????? ?? ?????? ??????? ???????? ?????? ??????? ???????? ?? ????? SELECT. ??? ????? ????? ????? ?? ???? ORDER BY ?? ????? ??? ?????? ??????? ?? ????? SELECT ??? ???? ??? ???? ??? ?????.

???????? ??? ???? ????? ??????? ANSI ???? ????? ??? ??? ???? ORDER BY ????? ?? ????? ORDER BY ??? ?? ???? ??? ??? ?? ?? ?????? ?????? ??????? ??????? ??????? ?? ??? ????? SELECT ?? ?? ?????? ????? ?????? ???????? ??? ??? ??????? ?? ????? SELECT.

???? ??????

?????? ??????? ???????? ?? ??????? ????? ????? ????? ?? ???? SQL ???????? ?? ????? ??? ??????? ?? ????? SELECT ????? ?? ????? ORDER BY.

??????? ????

?? ??????? ????? ????? ??????? ?? ??? ???? ?????? ?? ?? ????.

????? ????? ????? ??????

??????? ???????? ????? Transact-SQL ?????? ????? ????? ??????.

???? ??????? ????? LTRIM ? RTRIM ??? ?????? [C1] ?? ???? ORDER ????? ????? SELECT.
IF EXISTS( SELECT * FROM sysobjects WHERE name = 'T1' )
	DROP TABLE T1
GO

CREATE TABLE T1(  C1  NCHAR(1)  )

SET NOCOUNT ON

INSERT T1 VALUES( 'A' )
INSERT T1 VALUES( 'B' )

DECLARE @Str0 VARCHAR(4) 
DECLARE @Str1 VARCHAR(4) 
DECLARE @Str2 VARCHAR(4) 

SET @Str0 = ''
SET @Str1 = ''
SET @Str2 = ''

SELECT @Str0 = @Str0 + C1 FROM T1 ORDER BY C1
SELECT @Str1 = @Str1 + C1 FROM T1 ORDER BY LTRIM( RTRIM( C1 ) )
SELECT @Str2 = @Str2 + LTRIM( RTRIM( C1 ) ) FROM T1 ORDER BY C1

SELECT @Str0 'No functions applied to column.'
SELECT @Str1 'LTRIM() and RTRIM() applied to ORDER BY clause.'
SELECT @Str2 'SELECT list with LTRIM(RTRIM()) (Workaround)'

IF @Str1 <> @Str2
BEGIN
   PRINT ''
   PRINT 'Execution plan depends on where the functions are applied:'
   PRINT '=========================================================='
   PRINT ''

   SET @Str1 = ''
   SET @Str2 = ''

   SET STATISTICS PROFILE ON
   SELECT @Str1 = @Str1 + C1 FROM T1 ORDER BY LTRIM( RTRIM( C1 ) )
   SELECT @Str2 = @Str2 + LTRIM( RTRIM( C1 ) ) FROM T1 ORDER BY C1
   SET STATISTICS PROFILE OFF
END

SET NOCOUNT OFF

DROP TABLE T1
				

???????

???? ???????: 287515 - ????? ??? ??????: 20/?????/1424 - ??????: 3.2
????? ???
  • Microsoft SQL Server 2000 Standard Edition
  • Microsoft SQL Server 7.0 Standard Edition
????? ??????: 
kbmt kbcodesnippet kbprb KB287515 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????287515

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com