Dezryth
Dezryth

Reputation: 243

Can I use a stored procedure as part of my calculation in a select statement?

I have a stored procedure that uses a CTE to find total cost and cost per piece of an assembly (bill of materials).

My question is, is it possible to call the stored procedure as part of a select statement to calculate yield? I imagine it would look a little like this

SELECT 
(CASE WHEN ItemType = 'BOM' THEN (SalePrice * QTYSOLD) 
- ((EXEC dbo.sp_GETBOMUNITCOST ASMNumber) * QTYSOLD) /* Dynamically select parameter for each line */
FROM
dbo.SalesLine

Upvotes: 1

Views: 153

Answers (1)

Metaphor
Metaphor

Reputation: 6405

You would need to create a scalar function instead of a stored procedure to use it inline in a query.

Upvotes: 1

Related Questions