One last SQL syntax post for the evening...
We've all heard about SQL Server 2008 row constructors. They allow syntax like this to work:
CREATE TABLE name_table (name varchar(20), age int);goINSERT INTO name_table VALUES ('Bob', 54), ('Mary', 30), ('Sam', 15), ('Buddy', 9);go
But how about using them as a table source:
SELECT n.name, n.age, tab.speciesFROM name_table nJOIN ( VALUES ('Bob', 'person'), ('Mary', 'person'), ('Sam', 'cat'), ('Buddy', 'cat')) tab (name, species) ON n.name = tab.name;
You specify a table alias and name the columns, and its just another (synthesized on the fly) table.
Theme design by Jelle Druyts
Pick a theme: BlogXP sqlx BlogXP sqlx
Powered by: newtelligence dasBlog 2.0.7226.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008, Bob Beauchemin
E-mail