Return SQL 服务器中的多行?
Return Multiple Rows from Nothing in SQL Server?
在 Oracle SQL 开发人员中我可以使用:
select level as col1
, sysdate as col2
from dual
connect by level < 5;
..to return 4 行,其中 col1 从 1 计数到 4,col2 是当前日期,没有从 table.
中选择
如何在 SQL 服务器中完成此操作?
编辑:我的意图是 return 超过 1 行而不从 table 中选择。 Return 值并不重要。
在 SQL 服务器中,您通常可以使用递归通用 table 表达式来做到这一点:
with cte as (
select 1 as col1, getdate() as col2
union all select col1 + 1, col2 from cte where col1 < 4
)
select * from cte
col1 | col2
---: | :------------------
1 | 20/12/2019 17:28:37
2 | 20/12/2019 17:28:37
3 | 20/12/2019 17:28:37
4 | 20/12/2019 17:28:37
在 Oracle SQL 开发人员中我可以使用:
select level as col1
, sysdate as col2
from dual
connect by level < 5;
..to return 4 行,其中 col1 从 1 计数到 4,col2 是当前日期,没有从 table.
中选择如何在 SQL 服务器中完成此操作?
编辑:我的意图是 return 超过 1 行而不从 table 中选择。 Return 值并不重要。
在 SQL 服务器中,您通常可以使用递归通用 table 表达式来做到这一点:
with cte as (
select 1 as col1, getdate() as col2
union all select col1 + 1, col2 from cte where col1 < 4
)
select * from cte
col1 | col2 ---: | :------------------ 1 | 20/12/2019 17:28:37 2 | 20/12/2019 17:28:37 3 | 20/12/2019 17:28:37 4 | 20/12/2019 17:28:37