2017-03-19 155 views
0

我有一个表在SQL Server值函数,其返回多个行和单个列如以下移调单行多列分成多个列单式柱

1 
2 
3 

我使用语法select * from dbo.function使用返回的值通过这个函数的条款我的查询。

现在,除了函数返回的值之外,我还想将某些硬编码值放在的子句中。

例如:

Select * from dbo.table where ID in (Select * from dbo.function + **I want to add some more values here**) 

因此,如果函数返回

1 
2 
3 

我想补充可以说

4 
5 
在该列表中,使得最终的查询变为如下

select * from dbo.table where ID in (1,2,3,4,5) 

回答

2

使用or

Select * 
from dbo.table 
where ID in (Select * from dbo.function) or 
     ID in (4, 5) 

虽然你可以使用裂伤的union all子查询,上述使得查询更易于理解(在我看来)。另外,如果“函数”实际上是一个表格,那么优化器将更容易识别适当的索引。