I'd like to concatenate three columns - street, street number and city to one column "adress". The strange thing is that I cannot do it for some reason.
This is what I have tried so far:
SELECT street,
street_num,
city,
isnull(street,'') + '' + isnull(street_num,'') + '' + isnull(city,'') AS tst1, --doesnt work
concat(isnull(street,''),' ',isnull(street_num,''), ' ', isnull(city,'')) AS tst2, --doesnt work
(street_num + ' ' + street) AS tst3, --does work
(street_num + ' ' + city) AS tst4, --does work
(city + ' ' + street) AS tst5 --doesnt work
FROM [DB].[dbo].[adresses]
Note that + or concat doesnt work, it only shows the first column, street in these cases. However, if I start with street number and add street or city, it does work. But if I try to add third column, it is not shown.
If it helps, the table was pulled from Oracle by OPENQUERY and the table structure is as follows:
street VARCHAR(100), null
street_num VARCHAR(50), null
city VARCHAR(100), null
I am on MSSQL 2014.
EDIT
As asked in the comments, i cant show the data as I am dealing with addresses of our customers. Below are two dummy records plus expected result (adress) as example:
street | street_num | city | adress
--------------------------------------------------------------------
avenida pino alto | 45 | avila | avenida pino alto 45 avila
rue de abaixo | 86 | madrid | rue de abaixo 86 madrid
Furthermore, If i copy the records and do something like this, it works of course.
SELECT 'avenida pino alto' + ' ' + '45' + ' ' + 'avila'
isnull(CAST(street as varchar) ,'')+' '+isnull(CAST(street_num as varchar) ,'')+' '+isnull(CAST(cityas varchar) ,'')