Solved

sql command to rename a field once query results are displayed

Posted on 2008-10-21
2
1,134 Views
Last Modified: 2012-08-14
i have been able to rely on ms access for years, but job duties are getting a bit more cumbersome and trying to delve into the sql world.  in access all you have to do to rename a field name in the query setup is "new field name":"current field name" - basically monkey work.  how is it done in an sql statment?  for instance if the field in quest is "run_yr_mo" and is sourced from a table call "mtgmgr.acct.mstr" and i want the field name to display as "DATE" when the query results are returned, what is the command sequence?  help features seem to indicate the following:
SELECT MTGMGR.ACCT_ACCTMSTR.RUN_YR_MO as [DATE] . . .
0
Comment
Question by:mbilicic
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 25 total points
ID: 22767504
The sample above is how it's done: if you want to override the original column name, just follow it in the
select clause with AS TheNameYouWant.  Access does the same thing, except that the nice friendly
GUI hides the SQL being generated behind the scenes...
0
 
LVL 1

Assisted Solution

by:GeniusSteals
GeniusSteals earned 25 total points
ID: 22767559
You can use AS to alias all sorts of objects which will make them easier to reference, and your code easier to read.

Therefore you could have

SELECT mainTable.run_yr_mo AS Date
FROM mtgmgr.acct.mstr AS mainTable
ORDER BY Date

Notice that once a field is aliased you can then ORDER the results by the alias
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now