473,395 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

What is the use of using an AS clause in a SQL query?

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();

Apr 1 '07 #1
3 1303
weird0 wrote:
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 that case, because I believe ExecuteScalar fetched
values by index and not by name.

But if you were using ExecuteReader and fetched values
by name instead of by index, then it would be necessary.

Arne
Apr 1 '07 #2
"AS" indicates that you want the field returned under an alias.

In your example, it means that the "accno" data should be returned under the
alias name "AccountNumber".

"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();

Apr 1 '07 #3
"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
Apr 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bob | last post by:
Let me state up front that I know very little about XML. My experience is pretty much limited using the XML Serializer to serialize a user preferences class to a file and back again. I'm writing...
1
by: Chasing Gates | last post by:
I have created a database that brings in a new table weekly. I then made a separate query for each sales rep and a separate report for each rep. (The reports are all identical but call different...
41
by: Mountain Bikn' Guy | last post by:
What is the current preferred way to save user preferences in dotnet? Is the registry the right place to do this? Can anyone recommend a good article (or book) for this topic? Thanks.
5
by: JIM.H. | last post by:
Hello, I am trying to send Where clause as a parameter. Here is the detail: Select statment: // sqlSelectCommand1 // this.sqlSelectCommand1.CommandText = "SELECT * " + " FROM myTable " + "...
2
by: tomlebold | last post by:
The function or code below creates a saved query used as the record source for forms and reports. The funtions is called each time a user clicks on a button to display a form or report. This works...
5
by: Luqman | last post by:
I have created a master/detail asp.net page using detailview control and gridview control, out of which detailview is editable. I have created a dataset using Oracle Connection and I want to...
0
debasisdas
by: debasisdas | last post by:
Using Subqueries ================== The sub query is often referred to as a nested SELECT, Sub - SELECT, or inner SELECT statement. The sub query executes once before the main query. The...
0
MMcCarthy
by: MMcCarthy | last post by:
Rather than using the Access design view change the view to SQL. I am going to attempt to outline the general syntax used for SQL queries in Access. Angle brackets <> are used in place of some...
6
by: Jared | last post by:
Consider the following two functionally identical example queries: Query 1: DECLARE @Name VARCHAR(32) SET @Name = 'Bob' SELECT * FROM Employees WHERE = CASE WHEN @Name IS NULL THEN ELSE...
6
by: jackal_on_work | last post by:
Hi Faculties, I have two queries which give me the same output. -- Query 1 SELECT prod.name, cat.name FROM products prod INNER JOIN categories cat ON prod.category_id = cat.id WHERE cat.id...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.