Solved

Combining table fields within a query

Posted on 2013-06-22
5
323 Views
Last Modified: 2013-08-08
I have an access 2007 application that has a person table, with last_name, first_name attributes.  I would like to build a query where I can combine last_name and first_name, and represent the combined fields as one field "name".  I have tried the following:

name:last_name & ", " & first_name

but I get syntax errors from SQL.

Is there a way to do this?

Thanks in advance for your help.

Tom
0
Comment
Question by:tpigielski
[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
5 Comments
 
LVL 12

Expert Comment

by:pdebaets
ID: 39268771
If you are in SQL view try

last_name & ", " & first_name as [name]

however, I would recommend NOT using a reserved word as a field name. Try "fullname" instead of "name".
0
 

Author Comment

by:tpigielski
ID: 39268825
Poor choice of identifiers on my part.  "name" is not what I am using, but something else.  My query is much more complicated than this (multiple tables).  What I really need to know is whether or not I can do this kind of an operation from a query?

Thanks..Tom
0
 
LVL 12

Accepted Solution

by:
pdebaets earned 250 total points
ID: 39268840
If you are in SQL view try

last_name & ", " & first_name as FullName

In query design view try

FullName: last_name & ", " & first_name

If the syntax error persists, please post the SQL here so we can see what the problem is.
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 39268961
Problem could be that some fields are empty:

full_name: IIf(last_name+first_name Is Null, Nz(last_name & first_name, "Unknown"),last_name & ", " & first_name)

/gustav
0
 
LVL 24

Assisted Solution

by:Bitsqueezer
Bitsqueezer earned 250 total points
ID: 39269040
Hi,

the problem can also be sometimes the query designer. In some cases it does strange conversions to your input, so it's better to write such expressions in SQL and then switch back to the query designer and you see the result.

I would concatenate such strings on this way (in case of a full name concatenation):

SELECT Nz(last_name) & Iif(Nz(last_name)="" OR Nz(first_name) ="", "", ", ") & Nz(first_name) AS FullName FROM YourTable

Open in new window


BTW: You should not use VBA functions in cases where there are SQL pendants. The "IsNull" function should only be used in VBA, in SQL it is always "IIf(MyField IS NULL, ...".

In general I see no error with your syntax except using "name" as alias.

Cheers,

Christian
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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