SQL - Outer Apply

  • 1464
  • 0
  • SQL
  • 2015-03-25

摘要:SQL - Outer Apply

一值在這份工作之前,在撰寫SQL一值都沒有用的很深,Outer apply這種語法,我還從來沒使用過

但是用熟之後發現還挺好用的,因此寫個簡單的例子分享給大家。

 

Before change a new career.  I just use simple SQL Script. So ~ I never been used

"outer apply".  I found it's really convient after I get use to it. Here have a simple

sample to help people know how to use it.

 

【SAMPLE】 

 

SELECT *
FROM (SELECT *
FROM (SELECT 'I' AS Suject,
'LOVE' AS Verb,
'U' AS Noun) A) TB1
OUTER apply (SELECT noun
FROM (SELECT 'Love' AS Verb,
'And MY FAMILY' AS Noun) B
WHERE B.verb = TB1.verb) TB2

 



【RESULT】

 

 

 

BTW.  Here have a nice web page share with u guys.  it can help u to format ur SQL Script.

           這裡有個能自動格式話SQL的網頁,對於SQL亂七八糟的情況可以貼在這邊格式化

 

           http://www.dpriver.com/pp/sqlformat.htm