[sql] Distinct error ?

Pagina: 1
Acties:

  • Tinuske
  • Registratie: September 2002
  • Laatst online: 08-02 20:43
Het een probleem met de volgende sql :
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 ?

  • nescafe
  • Registratie: Januari 2001
  • Laatst online: 10:28
Je moet de volledige expressie als kolom in je select opnemen (misschien dat alleen @SortBy opnemen ook werkt).
Maar is dit niet meer view-werk? Dan kun je select * from view order by ... gebruiken.

[ Voor 14% gewijzigd door nescafe op 30-12-2004 14:43 ]

* Barca zweert ook bij fixedsys... althans bij mIRC de rest is comic sans


  • P_de_B
  • Registratie: Juli 2003
  • Niet online
Je moet idd de hele case when constructie in je select opnemen.

Oops! Google Chrome could not find www.rijks%20museum.nl