Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
SQL Server Newbies
»
DateName Query
DateName Query
Rate Topic
Display Mode
Topic Options
Author
Message
kerry_caskey
kerry_caskey
Posted Thursday, September 27, 2007 7:19 PM
Forum Newbie
Group: General Forum Members
Last Login: Thursday, September 27, 2007 7:18 PM
Points: 1,
Visits: 1
I am using the function in a Query: ORDER BY DateName (Month, ChargeDate).
I am trying to do one query with three columns: DateNumber (i.e. December would be number 12, etc.), DateName, and Total (the total comes from the SUM of some other items using WHERE statements).
I can create a single table with the DateNumber and Total columns, but when I try to add the DateName column, I get an error. The error says that the SELECT statement is invalid because the DateName is not contained in either an aggregate function or the GROUP BY statement. I can create a table with ONLY the DateName column and it works correctly...now if only I could combine these two queries. I even tried making the GROUP BY and ORDER BY statements the same DateName (Month, CHargeDate), but I still got the same error as before.
I either need a resource that gives examples of an entire Query (as opposed to just the ORDER BY DateName statement), also maybe one that would be useful in future situations, or maybe someone knows what I am talking about and can tell me why I might be getting that error.
Post #403852
Lowell
Lowell
Posted Thursday, September 27, 2007 7:27 PM
SSChampion
Group: General Forum Members
Last Login: Today @ 6:41 PM
Points: 11,648,
Visits: 27,760
in the ORDER BY section of a statement, you can refer to data by the alias that was assigned to it, isntead of the function. will that help you out?
ie SELECT MAX(something) as ThatThing,DateName (Month, ChargeDate) As DaDate
From Some Table
group by SomeKey
Order By ThatThing,DaDate
Lowell
--
There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #403856
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.