Friday, February 21, 2014

Example of reusing common table expression table name

;with word as
(
 select 'hello' as word union all
 select 'goodbye' 
 
)
, thing as 
(
 select 'world' as name union all
 select 'friends'
)
, wordthing as
(
 select w.word +  ' ' + t.name statement
 from 
  word w,
  thing t
)
Select wt.statement
from
 wordthing wt


Result: