Home Dashboard Directory Help
Search

ORDER BY items must appear in the select list if SELECT DISTINCT is specified by Roberson Ferreira _


Status: 

Closed
 as By Design Help for as By Design


1
0
Sign in
to vote
Type: Bug
ID: 767076
Opened: 10/11/2012 10:22:35 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

Can not use Distinct with sorting, conversion and alias.

The error occurs:

"Msg 145, Level 15, State 1, Line 1
ORDER BY items must appear in the select list if SELECT DISTINCT is specified."

This command works:
"Select Distinct Top 10 CdChamada = Convert(Bigint, CdChamada) From Pessoa Order by CdChamada"

This command, with alias, does not work:
"Select Distinct Top 10 CdChamada = Convert(Bigint, P.CdChamada) From Pessoa P Order by P.CdChamada"
Details
Sign in to post a comment.
Posted by Microsoft on 10/15/2012 at 2:06 PM
Hello Roberson,
The behavior you are seeing is by design. It also follows the ANSI SQL specification which is more stricter in lot of cases.

--
Umachandar, SQL Programmability Team
Sign in to post a workaround.