Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 11th, 2003, 03:05 PM
Authorized User
 
Join Date: Oct 2003
Location: , , Norway.
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select Distinct Order by...

Hi,
I've tried to order a querry, but it keeps giving me a bug..
Here goes:

*********************CODE************************* ********
Select Distinct right(left(ryCreatedDate,4),2) FROM RYKTE where right(left(ryCreatedDate,6),2) = '03' ORDER BY ryCreatedDate ASC
************************************************** *********

I'm getting this error (From querry analyzer)
*********************Error************************ *********
Server: Msg 145, Level 15, State 1, Line 1
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
************************************************** *********

I just can't figure it out.. Anybody seen this before?

------------------------
All help is Good help!
Regards
Michael
__________________
------------------------
All help is Good help!
Regards
Michael
Reply With Quote
  #2 (permalink)  
Old November 11th, 2003, 03:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

The error message says it all. You have an expression in the SELECT list, not the table's column - give the expression a column alias:
Code:
SELECT DISTINCT right(left(ryCreatedDate,4),2) as TheYear
    FROM RYKTE
    WHERE right(left(ryCreatedDate,6),2) = '03'
ORDER BY TheYear
(P.S. Are you storing this date as a string?)

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
Reply With Quote
  #3 (permalink)  
Old November 17th, 2003, 12:49 AM
Authorized User
 
Join Date: Oct 2003
Location: , , Norway.
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry I could not respond sooner, my internet link has been down for a while.
Yes I'm storing it at string. I've unfortunently taken over a base with a couple 100K entries. And my predessesor left me with this..?..

I found the fault, but as my link has benn down for quite awhile I haven't been able to post(damn those ISP's, ALWAYS fu...ing up!)
Here is what I did..
*****************WORKING***************
Select Distinct right(left(ryCreatedDate,4),2) FROM RYKTE where right(left(ryCreatedDate,6),2) = '03' ORDER BY right(left(ryCreatedDate,6),2) ASC
***************************************

Thanx for your reply, nice to know there is help out there when stuck..

------------------------
All help is Good help!
Regards
Michael
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR 145: ORDER BY ITEMS... SELECT DISTINCT... tbaquero SQL Server 2000 7 May 8th, 2008 02:30 AM
Select Distinct kirkmc Access 13 July 13th, 2006 01:26 PM
Select Distinct kirkmc Excel VBA 3 May 5th, 2006 07:55 PM
Select Distinct? hugh@kmcnetwork.com SQL Language 5 November 5th, 2005 09:58 AM
Distinct SELECT DISTINCT question... EndEffect Classic ASP Databases 4 August 18th, 2005 08:53 AM



All times are GMT -4. The time now is 05:54 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.