Solved

sql command to rename a field once query results are displayed

Posted on 2008-10-21
2
1,135 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Help 27 41
Calculation in Access 5 25
Experience with VBA code that changes unexplicably? 8 22
T-SQL:  Collapsing 9 22
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

785 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