"weird0" <am********@gmail.comwrote in message
news:11*********************@d57g2000hsg.googlegro ups.com...
What is the use of using an AS clause in a SQL query something like:
SELECT accno AS AccountNumber from Accounts
What difference does it make when i use the ExecuteScalar() function
and store it in a variable of the name of my own choice..... like:
string AccountName=cmd.ExecuteScalar();
None in this particular case...
However, using AS to create an alias of a column (or even a table) can be
particularly useful when e.g. you are joining two tables which contain
fields of the same name...
If you had a Customers table and a Sales table both of which had a field
called RecordID (after first firing the designer!), you might do something
like this:
SELECT
c.RecordID AS CustomerID,
c.Name,
c.Address,
s.RecordID AS SaleID,
s.ItemID,
s.Amount
FROM
Customers c
INNER JOIN Sales s ON c.RecordID = s.CustomerID