|
-
Jan 17th, 2009, 03:05 AM
#1
Thread Starter
Addicted Member
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
-
Jan 17th, 2009, 03:37 AM
#2
Re: Combined two columns
Are you sure that only one column will have a value in any one record?
-
Jan 17th, 2009, 04:36 AM
#3
Thread Starter
Addicted Member
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.
-
Jan 17th, 2009, 04:42 AM
#4
Re: Combined two columns
In your SELECT list, use ISNULL()
Code:
SELECT
field2,
field3,
ISNULL(Vegetable, Fruit) AS Foods,
field5,
field6...
-
Jan 18th, 2009, 02:38 PM
#5
Fanatic Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|