SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


DateName Query


DateName Query

Author
Message
kerry_caskey
kerry_caskey
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 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.
Lowell
Lowell
SSC Guru
SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)

Group: General Forum Members
Points: 74385 Visits: 40977
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
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search