The following SQL code works fine if I don't use the CONVERT to make my column two characters wide. When using it as follows the error message reads:
"ORDER BY items must appear in the select list if SELECT DISTINCT is specified." If I just use:
SELECT DISTINCT MONTH(CTNoteDate) it works fine.
How can I run this query with the column width set and sort the results? - SELECT DISTINCT CONVERT(varchar(2),MONTH(CTNoteDate)) MO,
-
DATENAME(month,CTNoteDate) MONTH
-
FROM CTNotes WHERE YEAR(CTNoteDate)=2014
-
ORDER BY MONTH(CTNoteDate)
Thanks! ~GregM
Please use code tags when posting code or formatted data.
If you're going to use an ORDER BY with a DISTINCT, whatever is in the ORDER BY must also be in the SELECT.
Therefore you have 2 solutions, include what's in your ORDER BY in your SELECT: - SELECT DISTINCT CONVERT(varchar(2),MONTH(CTNoteDate)) MO,
-
DATENAME(month,CTNoteDate) MONTH,
-
MONTH(CTNoteDate)
-
FROM CTNotes WHERE YEAR(CTNoteDate)=2014
-
ORDER BY MONTH(CTNoteDate)
Or change your ORDER BY to match the expression in the SELECT: - SELECT DISTINCT CONVERT(varchar(2),MONTH(CTNoteDate)) MO,
-
DATENAME(month,CTNoteDate) MONTH
-
FROM CTNotes WHERE YEAR(CTNoteDate)=2014
-
ORDER BY CONVERT(varchar(2),MONTH(CTNoteDate))
3 2260
Please use code tags when posting code or formatted data.
If you're going to use an ORDER BY with a DISTINCT, whatever is in the ORDER BY must also be in the SELECT.
Therefore you have 2 solutions, include what's in your ORDER BY in your SELECT: - SELECT DISTINCT CONVERT(varchar(2),MONTH(CTNoteDate)) MO,
-
DATENAME(month,CTNoteDate) MONTH,
-
MONTH(CTNoteDate)
-
FROM CTNotes WHERE YEAR(CTNoteDate)=2014
-
ORDER BY MONTH(CTNoteDate)
Or change your ORDER BY to match the expression in the SELECT: - SELECT DISTINCT CONVERT(varchar(2),MONTH(CTNoteDate)) MO,
-
DATENAME(month,CTNoteDate) MONTH
-
FROM CTNotes WHERE YEAR(CTNoteDate)=2014
-
ORDER BY CONVERT(varchar(2),MONTH(CTNoteDate))
Very sorry about forgetting the code tags.
Thank you very much -- it makes all the sense in the world, I just couldn't figure out HOW to include the select code in the order.
Have a great day!
No problem, good luck with the rest of your project!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: issac |
last post by:
Hi folks
Im trying to do a simple query involving the distinct keyword and an
access 2000 db, but have been frittering with it for amost and hour
and a half and I cant make it work.
This is...
|
by: mavis |
last post by:
Could you please help me with this xsd definition?
I need to define a set of elements occur in any order with multiple
occurrences, but the same kind of elements need to group together...
Sth...
|
by: JimN1 |
last post by:
Hi,
I am getting the following error message when I execute my query. I am trying to get my results in XML Explicit format. The error message is:Name cannot begin with the '.' character, hexadecimal...
|
by: TheLearner |
last post by:
(Newbie)
Greetings
I am trying to create an Index page in Serif Webplus10. Regretfully the application doesn't have that feature I need.
I would like to load 4/8 images ( picture +...
|
by: atulsaxena1981 |
last post by:
Dear All,
I am working exchange server & fetching task of outlook 2007
through MSXML2.XMLHTTP30 now I am facing the following error
"Name cannot begin with the '0' character, hexadecimal...
|
by: ebusiness |
last post by:
I am trying to create nicknames for tables in a remote database. The
federated database and remote database are both DB2 UDB V8.2, both OS
are AIX.
Could anyone tell me how to create a nickname...
|
by: =?Utf-8?B?UmljaEI=?= |
last post by:
Can someone confirm if my no spam alias is set up correctly to get answers
to questions. I have been talking to the concierge for over a week to get an
answer to a question. Each time I am told to...
|
by: meskeleton |
last post by:
Hello everyone...
When i try to access the site helm.manashosting.biz\
or http:\\69.50.194.212:8086\
The webpage does not display
On clicking diagnose the problem link, It says cannot...
|
by: penfold33 |
last post by:
Hi
I need to generate a CSV of names and address from a table and I would like only one result (it doesn't matter which) per distinct email address. If possible, they also need to be ordered by...
|
by: Steven Payne |
last post by:
I am getting a "mysqlcppconn-static.lib(mysql_driver.obj) : fatal error LNK1313: ijw/native module detected; cannot link with pure modules" error message in Visual C++ Stan Edit 2008. I am simply...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |