SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

markshen2006
Starting Member

15 Posts

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

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

Mark

tkizer
Almighty SQL Goddess

USA
36997 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
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 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  
 New 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.08 seconds. Powered By: Snitz Forums 2000