devxlogo

Pulling Values Together from Two Fields

Pulling Values Together from Two Fields

Question:
How do I merge two values from separate fields using SQL?

An example would be taking the LastName field and placing it before the FirstName field like this: “LastName, FirstName”.

I would then like to generate a whole new field based on this result.

Answer:
You can accomplish your task simply by ordering the fields in the select list so that last name comes in the select list first.

If you actually want to combine Last Name and First Name so that they look like they came from one entry in one field, then you can issue this instead:

SELECT RTRIM(lastname)+' '+RTRIM(firstname) 

Don’t forget the quotes and the embedded space, otherwise everything will run together most unattractively. I think this solution will get you home.

See also  Small Business Strategies with Venmo
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist