Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL Server
Expertise: Beginner
Oct 8, 1999

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.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date