Reputation: 13
I need to introduce a dummy row if my query 1 fails to fetch result.
select column1,column2,... from <ActualTable> Where condition='abc'... (1)
Union
select "dummy col1","dummy col2"..... from <dummy table> where col1 NOT IN (select column1 from
<ActualTable> where condition = 'abc'..) (2)
With the above query if query 1 fetches result query 2 wont. If query 1 has no result then i would get a dummy row.
Is there any other way to achieve the same result in Sybase?
Upvotes: 1
Views: 959
Reputation: 432271
Temp table if the "ActualTable" gives >1 row
select column1,column2,... INTO #temp
from <ActualTable>
Where condition='abc'... (1)
IF @@ROWCOUNT = 0
select "dummy col1","dummy col2"..... INTO #tmp
from <dummy table>
-- #temp will exist now
INSERT #temp
select column1,column2,...
from <AnotherTable>
Where condition='abc'... (1)
IF @@ROWCOUNT = 0
INSERT #temp
select "dummy col1","dummy col2".....
from <dummy table>
...
SELECT * FROM #tmp
Upvotes: 1
Reputation: 15085
Try this:
select top 1 * from
(
select 0,column1,column2,... from <ActualTable> Where condition='abc'... (1)
Union
select 1,"dummy col1","dummy col2"..... from <dummy table>
order by 1
)
If first query is successful, you will get it, if not, then the second will be returned
Upvotes: 0