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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

20 Experts available now in Live!

Get 1:1 Help Now