T-SQL如何在SELECT查询中运行过程/函数?

Ton*_*ony 6 t-sql

我现在无法检查它(现在没有编译器),但该查询是否会执行?

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

from myTable

group by myTable.id_customer
Run Code Online (Sandbox Code Playgroud)

该过程/函数返回NUMERIC(18,0)或NULL

总而言之,我需要从该表和该id中选择不同的 id_customer - 获取当前与该id_customer关联的数字/ null值

Mar*_*ith 10

从语法上讲,它适用于标量UDF,但不适用于存储过程.

select myTable.id_customer, mySchema.myFunction(myTable.id_customer) As myAlias
from myTable
group by myTable.id_customer
Run Code Online (Sandbox Code Playgroud)

但是,根据标量UDF的作用,可能会有更多高性能的方法.例如,如果它在另一个表中查找值,通常最好将此逻辑内联到查询中.