Calling a stored procedure from a SELECT query

  • Hi

    Is it possible to call a stored procedure in order to calculate a column in a SELECT query?

    Something like:

    SELECT EmployeeID, EmployeeName

    ,EXEC spCalculateTax(p1, p2, p3)

    FROM Employees

    Thanks.

  • Hi

    Guideline for calculations in SELECT section is a scalar user defined function instead of a procedure. It may be possible to call a procedure with OPENQUERY but maybe have a look for functions.

    Greets

    Flo

  • Hi,

    Write a function that takes the parameters needed and returns the value that you require and you can use that function within the Select.

  • We cannot directly call a stored procedure like that in a select statement, if possible try converting the proc to a function and use it.

    Or

    If youur main select query is in a stored proc, try getting the data returned by stored proc into a table of sorts and join the result sets.

    Sriram

  • Great thanks all!

    ....and what is the correct syntax for calling the function in my select statement? I want the result of the function to be placed in a column.

  • ah its ok...I worked it out.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply