Bun Bun - 6 months ago 26
SQL Question

Combine attributes using sql vba access

I have a sql statement that want to combine FirstName and LastName together while a listbox retrieve from a table.

rs.open"Select ID,Join(FirstName,LastName),Sex from TblPerson "
Set listbox.Recordset=rs


I know i use Join() it's wrong, but i just want to explain my purpose.
Thank you in advanced !!

Answer

You can concatenate with code like this:

"SELECT ID, FirstName + ' ' + LastName AS FullName, Sex FROM TblPerson"

If you are using SQL Server 2012 or higher then this will also work (based on your "access" tag, I assume you aren't):

"SELECT ID, CONCAT(FirstName, ' ', LastName) AS FullName, Sex FROM TblPerson"

Comments