SQL Server How to select the hardcoded array in SQL?

9ceoxa92  于 2023-10-15  发布在  其他
关注(0)|答案(1)|浏览(125)

In SQL, if I want to select a hardcoded value, I can do SELECT 1; for example, which would return a table with one column and one row with value 1 . How can I select the hardcoded array in SQL?

So, I want the output to contain one column with two rows, say with values 1 and 2 . How can I do that?

I tried SELECT 1, 2; but that returns a table with one row but two columns, what I do not want. I also tried SELECT (1, 2); and SELECT IN(1, 2); but none of them works.

I use the Microsoft Structured Query Language server.

vlju58qv

vlju58qv1#

select *
from (values (1),(2)) v(value)

or

select 1 value
union all
select 2 value

or (for SQL Server 2022+ and Azure SQL)

select value
from generate_series(1,2)

相关问题