Solved

Combining table fields within a query

Posted on 2013-06-22
5
319 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
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 49

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
This article will show you how to use shortcut menus in the Access run-time environment.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

914 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

14 Experts available now in Live!

Get 1:1 Help Now