Solved

conditional union

Posted on 2009-07-16
4
258 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
  • 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 500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

762 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

21 Experts available now in Live!

Get 1:1 Help Now