2010-10-11 55 views
5

我現在無法檢查它(現在沒有編譯器),但該查詢是否會執行?T-SQL如何在SELECT查詢中運行過程/函數?

select myTable.id_customer, [my_procedure_or_function](myTable.id_customer) 

from myTable 

group by myTable.id_customer 

該過程/函數返回一個數字(18,0)或NULL

總結一下,我需要選擇從該表不同 id_customer和該ID - 獲得數/空當前與該id_customer關聯的值

回答

10

從句法上看,它將用於標量UDF,但不適用於存儲過程。

select myTable.id_customer, mySchema.myFunction(myTable.id_customer) As myAlias 
from myTable 
group by myTable.id_customer 

然而,依賴於標量UDF在做什麼,可能會有更多的高性能方法。例如,如果它在另一個表中查找值,通常最好將此邏輯內聯到查詢中。

+0

@Tony - 請參閱編輯。 – 2010-10-11 14:41:39

+0

非常感謝馬丁! :) – Tony 2010-10-11 14:42:04

1

正如馬丁史密斯說,只要它是一個標量的用戶定義函數(UDF),它節選相同類型的單個參數爲「myTable.id_customer」,而不是一個表格或存儲的過程,執行連接具有執行UDF的權利,那麼它應該工作得很好。