Home > Archive > SQL server exams > February 2003 > Question about aliases





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Question about aliases
sjgross

2003-02-06, 12:01 pm

Hi folks,

In studying aliases I have the following query from the MS training guide

use northwind
select top 2 * from [Order Details]
select OrdD1.OrderID AS OrderID,

SUM(OrdD1.Quantity) AS "Units Sold",
SUM(OrdD1.UnitPrice * OrdD1.Quantity) AS Revenue

My question is in the second SUM statement where it says OrdD1.Quantity should it not be referred to as Units Sold?

Or is it different because the whole statement in the parentheses (OrdD1.UnitPrice * OrdD1.Quantity) is being assigned as the alias?
MKSD

2003-02-06, 3:54 pm

Hi,
You're mostly correct, i.e. the sum of (price times quantity) - not just the parenthesis but the whole summing operation on the multiplied result of (P*Q).
The "quotes" are used because there is a space in the column alias, the Revenue Alias is really required because without it you would have no column name in the resultset.
Aliasing is particularly useful to rename a column, provide a name where there isn't one, and also in cases where results are joined from multiple tables with the same column name, for example you may have two tables with an identically-named column (e.g. 'Sales'), you may alias the Sales columns as Domestic, and Export respectively, or whatever is appropriate to distinguish them.
The sample you're referring to demonstrates that you can alias an existing name, or provide one where there is none. I'm overstating the case here, sorry its an occupational hazard ;-)

HTH,

Martin
naresh_sky

2003-02-10, 8:16 am

Hi susan,MKSD.

I agree with MKSD.
aliasing is also used when ur using the
self join based on a column where in u
give alias to join .

Cheer's
Naresh
Sponsored Links





Free Braindumps | MCSE braindumps software forum

Copyright 2003 - 2008 examnotes.net