Home > SQL Development > DISTINCT doesn't work with ORDER BY

DISTINCT doesn't work with ORDER BY



I can't seem to get my query to work. It returns (translated from Swedish):




Code:


Microsoft JET Database Engine (0x80004005)
The ORDER BY-instruction (myDate)..."doesn't work with"...DISTINCT.








This is my query (somewhat simplified):




Code:


set rs=Server.CreateObject("ADODB.recordset")
sql="SELECT DISTINCT DATEPART(year, myDate) AS 'myColumn_alias' FROM myDB"
sql=sql & " WHERE myName='" & myName & "'"
sql=sql & " ORDER BY myColumn_alias"
rs.Open sql,conn, adOpenStatic, adLockReadOnly, adCmdTableDirect






Is it because I have a WHERE-clause? If so, how should I design my query (I need only the years to populate a "select from" dropdownbox)? Or is it something else?



Thanks

    
Guest


All I had to do was to use YEAR instead of DATEPART. After that it worked!

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved