Reputation: 35
I have an Employee Table having two column city1,city2.
I want to select combine city1,city2 into single column with out using union.
Any other option for this?
Upvotes: 0
Views: 46
Reputation: 95561
If we assume that the OP does mean that want the results in the same way as a UNION
(which I doubt), then you could use a VALUES
expression:
SELECT V.City
FROM YourTable YT
CROSS APPLY (VALUES(YT.City1),(YT.City2)) V(City);
--WHERE V.City IS NOT NULL; --?
Upvotes: 1
Reputation: 26450
Join the two strings together. You can use CONCAT()
to achieve this. In this example, we add a whitespace between the two, this can be changed to your needs.
SELECT CONCAT(city1, ' ', city2) as city
FROM myTable
Alternatively you can use +
to join strings together, although I recommend CONCAT()
(in case any of them are null).
SELECT city1 + ' ' + city2 as city
FROM myTable
Upvotes: 2