How to select several hardcoded SQL rows?

前端 未结 8 1551
囚心锁ツ
囚心锁ツ 2020-12-28 11:55

If you execute this query

SELECT \'test-a1\' AS name1, \'test-a2\' AS name2

the result will be a one row-selection with two columns having

相关标签:
8条回答
  • 2020-12-28 12:26

    Values keyword can be used as below.

    select * from 
    (values ('test-a1', 'test-a2'), ('test-b1', 'test-b2'), ('test-c1', 'test-c2')) x(col1, col2)
    
    0 讨论(0)
  • 2020-12-28 12:29

    You can use a temp table, fill it up with your results and then select from it

    create table #tmpAAA (name1 varchar(10), name2 varchar(10))
    insert into #tmpAAA (name1, name2) 
    values ('test_a', 'test_b'),
           ('test_c', 'test_d'),
           ('test_e', 'test_f'),
           ('test_g', 'test_h'),
           ('test_i', 'test_j');
    select * from #tmpAAA;
    

    This will return

    name1   name2
    ==================
    test_a  test_b
    test_c  test_d
    test_e  test_f
    test_g  test_h
    test_i  test_j
    
    0 讨论(0)
提交回复
热议问题