Solved

Combining table fields within a query

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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 …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

810 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