In my last post, I have explained how CTE can be used in SQL Server 2005. Just take one query used in that post leads to the another topic.
Select EmployeeId,Year(OrderDate) AS OrderYear,
Count(*) as [Sales]
From dbo.Orders
Where EmployeeId=1
Group by EmployeeId,Year(OrderDate)
Order By OrderYear
In the above query the column Year(OrderDate) is having a alias OrderYear. But this alias is not used in the Group By Clause why? Again the alias is used in Order By Clause. Why don't we use the column alias in the select list can not be used in Group By as in Order By?
Post your comments...!
3 comments:
Very excellent question... i learnt a new thing in sql today... thanx...keep on posting...
gr8 Man,
Are you not writing nowadays?
No articles/posts?
Post a Comment