I have this current SP:
ALTER PROCEDURE [dbo].[GetHighestDrop]
@val1 AS FLOAT ,
@val2 AS FLOAT ,
@val3 AS FLOAT
AS
BEGIN
select case when @val1 < @val2 then
case when @val1 < @val3 then @val1
else @val3
end
when @val2 < @val3 then @val2
else @val3
end
END
I am calling it with this syntax:
SELECT
GetHighestDrop @val1=((clmnA/clmnB)-1)*100,@val2=2,@val3=3
FROM dbo.tstTable
clmnA and clmbB contain numbers, if I run them seperately, like:
SELECT ((clmnA/clmnB)-1)*100 FROM dbo.tstTable
I get a result, which is a float, but when I run it through GetHighestDrop, it fails.
Any idea why?
You can only call a stored procedure with
exec. There is no way to run a stored procedure inside aselect.Consider converting your procedure to a scalar user-defined function.
Example function use (don’t forget the schema name, usually “dbo”):