Solved

How can I select 2 differnt tables columns value into one column of a new table if one of the source column is NULL?

Posted on 2008-10-17
2
157 Views
Last Modified: 2010-05-18
Hi, I have Table a with column id, and table B with column id2.  I want to select a couple columns from A and from b including those id columns.  However, If the A.id IS NULL then I would like to use the B.id2 and write these value to the same column in a new 3rd table.  Is this possible?  Thank lyou.
The query is what I have currently.
Select A.[Name] as [Interest], A.ParentResearchInterest_id as RchChildId, B.ApplicationId as ApplicationId
into dbo.CtsiRschInterest
from dbo.ResearchInterests A
FULL JOIN dbo.tmpCtsiRcshInt B
ON A.Id = B.[ApplicationId]

Open in new window

0
Comment
Question by:lapucca
  • 2
2 Comments
 
LVL 14

Expert Comment

by:Binuth
ID: 22747182
try this sample....
SELECT * 
FROM
	(
	SELECT A.Id AS ABID FROM TableA A WHERE A.Id IS NOT NULL
	UNION ALL
	SELECT B.Id AS ABID FROM TableA A WHERE A.Id IS NOT NULL
	) AB
INNER JOIN TableC C ON AB.ABID = C.ID

Open in new window

0
 
LVL 14

Accepted Solution

by:
Binuth earned 500 total points
ID: 22747186
last query was wrong try this
SELECT * 
FROM
	(
	SELECT A.Id AS ABID FROM TableA A WHERE A.Id IS NOT NULL
	UNION ALL
	SELECT B.Id AS ABID FROM TableA B WHERE B.Id IS NOT NULL
	) AB
INNER JOIN TableC C ON AB.ABID = C.ID

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question