Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query or SP Help Please

Status
Not open for further replies.

MrktMind

Technical User
Joined
May 17, 2010
Messages
2
Location
US
I need to return a total of 10 rows. If not enough rows are returned from the first select statement I need to fill in the remaining empty rows with rows from an additional select statement.

Some general ideas of possibilities to solve this would be greatly appreciated!

John
 
Using temp table
Code:
declare @cnt int
select top 10 myFields into #temp from ...
select @cnt = @@ROWCOUNT

if @cnt < 10
select * from #temp
union
select top (10 -@cnt) ... from another table

else
   select * from #temp

PluralSight Learning Library
 
Simple
Code:
Select top 10 *
from(Select top 10 * ,a idx
     from tablea
     union
     Select top 10 * ,b idx
     from tableb
     )dt
order by idx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top