0

I have a sample Store Procedure:

dbo.spSampleProcedure
 @ID INT,
 @Country VARCHAR(50)

This SP will return a MONEY value(1 column only).

Now I want to implement it this way:

 SELECT 
    c.ID,
    Amount = EXEC spSampleProcedure @ID = c.ID, @Country = c.Country
 FROM Customer c

IS THIS POSSIBLE?

7
  • Have you tried it? Commented Oct 8, 2018 at 7:31
  • What you are looking for is a user defined function Commented Oct 8, 2018 at 7:31
  • @PeterSmith Surprisingly, It doesnt work :( Commented Oct 8, 2018 at 7:35
  • @AsRa Do you mean converting the sp to function right? Commented Oct 8, 2018 at 7:36
  • See here Commented Oct 8, 2018 at 7:36

1 Answer 1

0

You should consider NOT naming your stored procedures using sp_ as prefix. That is a system reserved prefix and it might cause performance issues. You can read more about it on this article by Aaron Bertrand.

In order to do what you need you could first create a user defined function (as mentioned to you in the comments) that would do the following:

create function myfunc(@Id int, @Country varchar(50))
returns money
as
begin

declare @amount money 

select @amount = amount
from Customer 
where Id = @Id and Country = @Country

return @amount
end

Only then you can try what you wanted to do:

select  c.id,
        amount = dbo.myfunc (c.id, c.country)
from customer c
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! now I know that it is impossible in stored procedure way because i wanna use the SP for maintenance and re-usability.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.