Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

730 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