Solved

sql command to rename a field once query results are displayed

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

763 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

6 Experts available now in Live!

Get 1:1 Help Now