如果我的查询1无法获取结果,我需要引入一个虚拟行。
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)
使用上面的查询,如果查询1获取结果查询2不会。如果查询1没有结果,那么我会得到一个虚拟行。
有没有其他方法可以在Sybase中实现相同的结果?
答案 0 :(得分:1)
临时表,如果“ActualTable”给出&gt; 1行
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
答案 1 :(得分:0)
试试这个:
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
)
如果第一次查询成功,您将获得它,如果没有,则返回第二次