T-SQL How to start a procedure / function in a SELECT query?

I canโ€™t check it right now (I donโ€™t have a compiler right now), but will this query be executed?

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

from myTable

group by myTable.id_customer

this procedure / function returns NUMERIC (18,0) or NULL

to summarize, I need to select a different id_customer from this table, and for this id - get the number / null value associated with this id_customer

+5
source share
2 answers

Syntactically, it will work for scalar UDF, but not a stored procedure.

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

However, depending on what the scalar UDF does, there may be more efficient approaches. If it is looking for a value in another table, for example, it is best to simply insert this logic into the query.

+10

, (UDF), , "myTable.id_customer", , UDF, .

+1

All Articles