Link to home
Start Free TrialLog in
Avatar of splanton
splantonFlag 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?
Avatar of DOSLover
DOSLover
Flag of United States of America image

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

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
IsNull(column,'')
Avatar of 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. :)