?
Solved

conditional union

Posted on 2009-07-16
4
Medium Priority
?
268 Views
Last Modified: 2012-05-07
I have one select - if null results - want to union it with another select - is that possible?  To have a conditional union?
0
Comment
Question by:tbaseflug
[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
4 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24870572
You dont really need a join here
 Just check @@ROWCOUNT

 SELECT Col1,Col2..FROM table1
IF @@ROWCOUNT = 0
 SELECT Val1 as Col1 , val2 as Col2 ... from someOtherTable
0
 

Author Comment

by:tbaseflug
ID: 24870616
well - I am returning it back to a asp.net page and really didn't want to have to check for another conditional datatable if possible
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 24870771
You can do all these in one step
there is actually no direct way to implement what you are intending , your other option is to add another column, to indicate from which statement the results are coming back

SELECT Col1, Col2 , 1 as Status
from Table1
UNION ALL
SELECT Col5, Col2, 2 as Status
from table2

Now you can do a check on status column at the asp side
0
 

Author Comment

by:tbaseflug
ID: 24870822
thanks - let me give it a shot
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

649 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