Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
David P
 
Posts: n/a
Default MS Query - Alias syntax

Hi All,

Does anyone know what is the correct syntax to rename a field name in MS
Query? I go thru the wizard and try to modify the sql. The alias or 'as' is
ignored when the query is run.
--
David
  #2   Report Post  
Jamie Collins
 
Posts: n/a
Default

David P wrote:
Does anyone know what is the correct syntax to rename a field name in

MS
Query? I go thru the wizard and try to modify the sql. The alias or

'as' is
ignored when the query is run.


In MSQuery syntax, the apostrophe/single quote/Chr$(39) character is
used to delimit the as the alias So, if my SQL looks like this:

SELECT Customers.Address
FROM `C:\Tempo\nwnd4`.Customers Customers

I can edit it to look like this:

SELECT Customers.Address AS Residence
FROM `C:\Tempo\nwnd4`.Customers Customers

When I look at it again, MSQuery has changed it to this:

SELECT Customers.Address AS 'Residence'
FROM `C:\Tempo\nwnd4`.Customers Customers

Unfortunately, the column name is returned to my worksheet with the
quotes. I can workaround this by using the syntax of me RDMS, in this
case MS Access/Jet, rather than MSQuery syntax. So I change my SQL to
this:

SELECT Address AS [Residence] FROM Customers;

My SQL and column name in the worksheet is now how I want it to be. The
down side is that my query can no longer be displayed 'graphically'
(whatever that means), the consequence of which is I lose support for
parameters (which I don't use).

BTW take a look at this KB article in case it applies to you:

Using a field alias in Query does not work with some third-party
databases
http://support.microsoft.com/default...b;en-us;298955

Jamie.

--

  #3   Report Post  
David P
 
Posts: n/a
Default

Thanks, but it still did not work for me. If it helps, I also had a hard
time calling up the Prompt dialog box. In the graphics, I coded [] in the
value field and that translated into = ? in the sql. This works for simple
query but for some reason the ? does not work with complex queries.

Thanks again, I will keep trying to figure it out.

"Jamie Collins" wrote:

David P wrote:
Does anyone know what is the correct syntax to rename a field name in

MS
Query? I go thru the wizard and try to modify the sql. The alias or

'as' is
ignored when the query is run.


In MSQuery syntax, the apostrophe/single quote/Chr$(39) character is
used to delimit the as the alias So, if my SQL looks like this:

SELECT Customers.Address
FROM `C:\Tempo\nwnd4`.Customers Customers

I can edit it to look like this:

SELECT Customers.Address AS Residence
FROM `C:\Tempo\nwnd4`.Customers Customers

When I look at it again, MSQuery has changed it to this:

SELECT Customers.Address AS 'Residence'
FROM `C:\Tempo\nwnd4`.Customers Customers

Unfortunately, the column name is returned to my worksheet with the
quotes. I can workaround this by using the syntax of me RDMS, in this
case MS Access/Jet, rather than MSQuery syntax. So I change my SQL to
this:

SELECT Address AS [Residence] FROM Customers;

My SQL and column name in the worksheet is now how I want it to be. The
down side is that my query can no longer be displayed 'graphically'
(whatever that means), the consequence of which is I lose support for
parameters (which I don't use).

BTW take a look at this KB article in case it applies to you:

Using a field alias in Query does not work with some third-party
databases
http://support.microsoft.com/default...b;en-us;298955

Jamie.

--


  #4   Report Post  
Jamie Collins
 
Posts: n/a
Default


David P wrote:
for some reason the ? does not work with complex queries


I think this is the result of a query not being able to be displayed
'graphically' i.e. loss of support for parameters. You get the
'graphically' message when the query is complex or uses SQL other than
MSQuery's implementation.

Jamie.

--

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query of External Data Excel GuRu Excel Discussion (Misc queries) 2 January 3rd 05 07:43 PM
Microsoft Query Help Patti Excel Worksheet Functions 4 December 25th 04 09:54 AM
How to use a Access Query that as a parameter into Excel database query Karen Middleton Excel Discussion (Misc queries) 1 December 13th 04 07:54 PM
Previous Post - Correct Syntax Query Clarence Crow Excel Worksheet Functions 0 December 7th 04 05:35 AM
Editing MS Query Patti Excel Worksheet Functions 2 December 2nd 04 01:31 PM


All times are GMT +1. The time now is 07:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"