Avatar of splanton
splanton
Flag for United Kingdom of Great Britain and Northern Ireland asked on

SQL Concatonation in a SELECT not behaving as expected.

I am concatonating some field values into a 'description' for an invoice. The only problem I can see is that the description appears empty when there are no InvoiceNotes.

Basically unless all the fields have values it appears to ignore the whole entry. ALL My WasteOrderDetail.JobRef rows have values but not all my WasteOrderDetail.InvoiceNotes rows will have.

The code I have is along these lines:

SELECT JobRef + ' - ' + ContainerSize.Description + ' ' + Container.Description + ' for ' + WasteType.Description +'. Notes: ' + WasteOrderDetail.InvoiceNotes as InvDescription
FROM WasteOrderDetail 
INNER JOIN Container ON WasteOrderDetail.ContainerId = Container.ContainerID
INNER JOIN ContainerSize ON WasteOrderDetail.ContainerSizeId = ContainerSize.ContainerSizeId
INNER JOIN WasteType ON WasteOrderDetail.WasteTypeId = WasteType.WasteTypeId 
WHERE ... etc

Open in new window


Is there any way round this?
Microsoft SQL ServerMicrosoft SQL Server 2008Microsoft SQL Server 2005

Avatar of undefined
Last Comment
splanton

8/22/2022 - Mon
DOSLover

Try || instead of + for concatenating.
SELECT JobRef  || ' - ' || ContainerSize.Description || ' ' || Container.Description || ' for ' ||   WasteType.Description || '. Notes: ' || WasteOrderDetail.InvoiceNotes as InvDescription
SOLUTION
Grazzhoppa

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Andrei Fomitchev

IsNull(column,'')
splanton

ASKER
Great answers guys. Thanks again.

I found that || did not work :)

Then I used Grazzhoppa's solution and then found the update from Qlemo and used that instead. Both work very well. :)
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy