Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
markshen2006
Starting Member
15 Posts |
Posted - 2008-04-28 : 17:06:15
|
Hi I have a staff table and it has columns like firstname, lastname etcI did the query and it works. but firstname and lastname are too closeSELECT (FirstName + Lastname) as fullnameFROM StaffListI need the format "firstname , lastname " so I write the second querySELECT (FirstName + " , " + Lastname) as fullnameFROM StaffListBut it doesn't work.Please help me and let me know how to make the second query work.Thanks a lotMark |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-04-28 : 17:19:54
|
Use single quotes instead of double quotes.SELECT FirstName + ' ' + LastName AS FullNameFROM StaffListTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-29 : 00:07:31
|
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 resultSELECT COALESCE(FirstName,'') + " , " + COALESCE(Lastname,'') as fullnameFROM StaffListAlso you dont really require the braces around concatenated field. |
|
|
|
|
|