Category Archives: How-to

SELECTing from a VALUES clause

This post falls into the category of something that I am always forgetting how to do, so this post is a reminder to self.

It is possible to create a virtual table in SQL Server using just the VALUES clause. The secret sauce is proper placement of parenthesis (which is where I always go wrong).

select *
from
(
	values
	(1, 'Virgil', 'Davila', '18 E Bonnys Rd', 'Natchez', 'MS'),
	(2, 'Jill', 'White', '675 W Beadonhall Rd', 'Providence', 'RI'),
	(3, 'David', 'Walden', '12663 NE Sevenside St', 'Bloomington', 'IN')
) tbl (CustomerID, FirstName, LastName, Address, City, State);

Now just wrap that up in a CTE or subquery and it can be used pretty much like any SQL table, such as the source for an INSERT or UPDATE statement.