Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 11th, 2003, 03:05 PM
Authorized User
 
Join Date: Oct 2003
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
 
Old November 11th, 2003, 03:13 PM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old November 17th, 2003, 12:49 AM
Authorized User
 
Join Date: Oct 2003
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





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? [email protected] SQL Language 5 November 5th, 2005 09:58 AM
Distinct SELECT DISTINCT question... EndEffect Classic ASP Databases 4 August 18th, 2005 08:53 AM





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