Saturday, May 30, 2020

How to write a select with values in SQL Server

Using the SELECT Statement Without a FROM Clause with Multiple Rows

This is an example of a SELECT statement used without a FROM clause, returning multiple rows.


VALUES ( <row value expression list> ) [ ,...n ]   

<row value expression list> ::=  
    {<row value expression>} [ ,...n ]  

<row value expression> ::=  
    { DEFAULT | NULL | expression }

This code creates a dataset with two columns named c1 and c2, and two rows.


SELECT *
  FROM (VALUES (1,2),
               (3,4)
       ) t1 (c1, c2)


Another example with string and numeric values:

SELECT * FROM ( VALUES ('Helmet', 25.50), ('Wheel', 30.00) ) ab(a, b);

Popular Posts