Concatenating a string in SQL - value blank

What is wrong with the following?

SELECT        ID, Forename + ' ' + Surname + '( ' + WName + ')' AS FullName
FROM            Customers
WHERE        (Business_ID = 137)
ORDER BY Forename

It works fine if Forename and Surname are not null but if they are null but WName has a string 'Lorna', FullName is just blank when it should be 'Lorna'??
Lorna70Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AshokSr. Software EngineerCommented:
Try this

SELECT        ID, IsNull(Forename,'') + ' ' + IsNull(Surname,'') + '( ' + WName + ')' AS FullName
FROM            Customers
WHERE        (Business_ID = 137)
ORDER BY Forename
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lee SavidgeCommented:
Either the above or look at

set concat_null_yields_null off

http://technet.microsoft.com/en-us/library/ms176056.aspx

Understant concatenation and null values.
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
When NULL is involved with any expression, the result will always be NULL.

The only way around this to either trap it and use a different expression, or convert it to an empty string using either IsNull (ashok111's answer above) or COALESCE(column_name, '')
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Brian CroweDatabase AdministratorCommented:
It helps to think of NULL as 'Unknown' and not 'Empty'.

unknown plus some value is still unknown
0
Scott PletcherSenior DBACommented:
SELECT        ID, ISNULL(Forename + ' ', '') + ISNULL(Surname, '') +
                     ISNULL('( ' + WName + ')', '') AS FullName
FROM            Customers
WHERE        (Business_ID = 137)
ORDER BY Forename
0
Lorna70Author Commented:
Thanks everyone - really helpful :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.