-
Combined two columns
Hi anyone here knows how to combine the two columns in a table with the same data type: varchar(255).
When you query the example below:
Code:
Vegetable Fruits
Potato NULL
Squash NULL
Cabbage NULL
NULL Apple
NULL Banana
NULL Mango
The Result will be:
Code:
Foods
Potato
Squash
Cabbage
Apple
Banana
Mango
Is it possible? Thanks in advance
-
Re: Combined two columns
Are you sure that only one column will have a value in any one record?
-
Re: Combined two columns
How can I do this in an sql query? In case it is not possible to combine the two. In one column there is a condition like this: If Vegetable Column is Null use Fruit Column and if Fruit Column is Null use Vegetable Column.
Code:
CASE Vegetable WHEN NULL
Fruit
ELSE
Vegetable
END AS 'Foods'
It returns null in my case. Don't know if it is possible? Or there is something I missed.
-
Re: Combined two columns
In your SELECT list, use ISNULL()
Code:
SELECT
field2,
field3,
ISNULL(Vegetable, Fruit) AS Foods,
field5,
field6...
-
Re: Combined two columns
i usually combine col from different table through union
Code:
select itm as foods from vege
union
select itm as foods from fruit