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
156 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now