Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 combine two column in Select statetment?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

15 Posts

Posted - 04/28/2008 :  17:06:15  Show Profile  Reply with Quote

I have a staff table and it has columns like firstname, lastname etc

I did the query and it works. but firstname and lastname are too close

SELECT (FirstName + Lastname) as fullname
FROM StaffList

I need the format "firstname , lastname " so I write the second query

SELECT (FirstName + " , " + Lastname) as fullname
FROM StaffList

But it doesn't work.Please help me and let me know how to make the second query work.

Thanks a lot


Almighty SQL Goddess

38200 Posts

Posted - 04/28/2008 :  17:19:54  Show Profile  Visit tkizer's Homepage  Reply with Quote
Use single quotes instead of double quotes.

SELECT FirstName + ' ' + LastName AS FullName
FROM StaffList

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 04/29/2008 :  00:07:31  Show Profile  Reply with Quote
Make sure you dont have any NULL values appearing in any of your fields as concatenation with null yields nulls while CONCAT_NULL_YIELDS_NULL is ON. So its better to do like this to avoid NULLs in result
SELECT COALESCE(FirstName,'') + " , " + COALESCE(Lastname,'') as fullname
FROM StaffList

Also you dont really require the braces around concatenated field.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000