Search code examples
sqlsql-servert-sqlselectunpivot

SQL Select to return a static list of values?


Is there a way to perform a select and return a static list? Something like the following:

select * from ('CA', 'FB', 'FC')

It should return

CA
FB
FC

Solution

  • If you want each value on a separate row, you can use table constructor values():

    select val
    from (values ('CA'), ('FB'), ('FC')) as t(val)
    

    If you wanted more columns, you would use tuples rather than singletons:

    select val1, val2
    from (values 
        ('CA', 'CB'), 
        ('FA', 'FB'),
        ('FC', 'FD') 
    ) as t(val1, val2)