Het een probleem met de volgende sql :
Ik krijg de error :
error 145 : Order By items must appear in the select list if select distinct is specified
Maar C.plaats en C.adres staan toch in de select ? Wat doe ik fout ?
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| SELECT
DISTINCT C.CompanyId,'' as Naam,
C.Naam as CompanyName,
C.Adres,C.Adres2,C.Huisnummer as Nr,C.Postcode,C.Plaats,CC.Naam as Land
FROM
AppCompany C With (NOLOCK)
LEFT OUTER JOIN
AppJonCompanyCategory CA With (NOLOCK) ON C.CompanyId = CA.CompanyId
LEFT OUTER JOIN
CatCountry CC With (NOLOCK) ON C.CountryId = CC.CountryId
LEFT OUTER JOIN
CatCountry CCB With (NOLOCK) ON C.BezoekCountryId = CCB.CountryId
LEFT OUTER JOIN
CatCountry CCF With (NOLOCK) ON C.FactuurCountryId = CCF.CountryId
LEFT OUTER JOIN
CatCountry CCO With (NOLOCK) ON C.OverigCountryId = CCO.CountryId
/*WHERE
blahblah
*/
Order By --C.Naam
CASE WHEN @SortBy = 'Naam' THEN C.Plaats
WHEN @SortBy = 'Adres' THEN C.Adres
END DESC |
Ik krijg de error :
error 145 : Order By items must appear in the select list if select distinct is specified
Maar C.plaats en C.adres staan toch in de select ? Wat doe ik fout ?