Solved

Combining table fields within a query

Posted on 2013-06-22
5
324 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 51

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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 …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

628 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