September 6, 2010 at 4:52 am
amresh_jhingan (9/6/2010)
I parsed the query before running it.. and it gave me "Command(s) completed successfully.". Not sure why.. ?
Syntax check only. And the syntax is okay. But that doesnt mean that it will run.
You can for instance parse say "select something from nothing" without having a table called "nothing".
September 6, 2010 at 5:55 am
Nice question, I got it right.
I did want to point out that since the correct answer is that it will generate an error, no rows will be displayed because of that error. it could then be argued that the "No rows will be displayed" answer could be considered a correct choice as well.
September 6, 2010 at 9:35 am
Thanks for the question
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
September 7, 2010 at 7:55 am
Good question, thanks. I have caused this error many times while composing my queries, so when I realized there was an alias in the GROUP BY clause, I figured that had to be the answer.
- webrunner
(Edit) P.S. Thanks, Hugo, for the detailed explanation of why this error happens.
-------------------
A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
September 7, 2010 at 10:30 am
Nice question. And nice description of logical order from Hugo.
Tom
September 10, 2010 at 12:39 am
Thanks to all for the positive comments and thanks Hugo for the logical explanation you gave. Helps a lot!
Tom please tell me what this means. "Na tog mi gun tuit mi ach ma thuiteas tog! Thig crìoch air an t-saoghal ach mairidh gaol is ceòl "
:-PManie Verster
Developer
Johannesburg
South Africa
I can do all things through Christ who strengthens me. - Holy Bible
I am a man of fixed and unbending principles, the first of which is to be flexible at all times. - Everett Mckinley Dirkson (Well, I am trying. - Manie Verster)
September 10, 2010 at 12:49 am
Manie Verster (9/10/2010)
Tom please tell me what this means. "Na tog mi gun tuit mi ach ma thuiteas tog! Thig crìoch air an t-saoghal ach mairidh gaol is ceòl "
Google translate recognises it as Scottish Celtic, but is not yet able to translate that to either English or Dutch.
Bing Translator thinks it's Hungarian and translates it to English as "Na train what gun tuit what ach thuiteas train today! Thig crìoch air an t-saoghal ach mairidh gaol also ceòl".
Guess which of the two competing sites I believe 😉
September 10, 2010 at 7:28 pm
Manie Verster (9/10/2010)
Tom please tell me what this means. "Na tog mi gun tuit mi ach ma thuiteas tog! Thig crìoch air an t-saoghal ach mairidh gaol is ceòl "
As Hugo said, it's Scotland's Celtic language, usually in English called Scottish Gaelic, or Gaelic for short (which of course creates confusion with Manx and Irish Gaelics) or in itself Gàidhlig na h-Alba. The first line means literally "Don't lift me unless I fall but if I fall do lift" but really "don't correct me unless I'm wrong but if I'm wrong do". The second line is a very old saying: "An end will come upon the world but love and music will survive".
Tom
September 14, 2010 at 7:54 am
I was up late last night working. I am looking at the question and thinking, "Gee, I didn't think you could group that way" and in my fatigue I chose the wrong answer instead of realizing that you can't group that way.
September 16, 2010 at 5:22 am
There is a "workaround":
SELECT DV.[Year],
SOH.SalesPersonID,
AverageOrderAmt = SUM(SOH.TotalDue)
FROM Sales.SalesOrderHeader SOH
CROSS
APPLY (SELECT DATEPART(yyyy,OrderDate)) DV ([Year])
GROUP BY
DV.[Year],
SOH.SalesPersonID
ORDER BY
DV.[Year] ;
Over to you, Hugo.
Paul
September 30, 2010 at 7:54 am
Great question and even better follow up discussions. Thanks!
November 2, 2010 at 12:58 pm
Based on Hugo's LOGICAL progression where the group by preceeds the select. The alias is not yet defined so grouping is not possible against a column that does not yet exist. The Order By occurs post Select where the alias has been defined so it is acceptable. An alternative solution is Group by datepart(yyyy,orderdate).
Viewing 12 posts - 16 through 26 (of 26 total)
You must be logged in to reply to this topic. Login to reply