Solved

sql command to rename a field once query results are displayed

Posted on 2008-10-21
2
1,147 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

696 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