I have this function which is used on my view.
FUNCTION [dbo].[CalculateAmount] (
@ID INT,
@PRICE DECIMAL(24,4))
declare @computedValue decimal(24,4)
set @computedValue = case when
(select TABLE1.ID
FROM dbo.[TABLE1] TABLE1
JOIN dbo.[TABLE2] TABLE2 ON TABLE2.ID = TABLE1.ID
WHERE TABLE1.ID = @ID // some conditions here //
Is null
then @PRICE
else
@PRICE * CAST('1.0368' as decimal(24,4))
end
So basically, I wanted to check if the ID passed as parameter is existing on TABLE1. If it returned a row, multiply the Price to 1.0368, if not then the Price will remain as is.
My problem here is the performance. I am using this on view which returns 17000 rows. Now my view is currently running, 45 minutes on 12000th row.
Any ideas or suggestion to improve the performance of my view?
EDIT
I am calling this on my view like this:
[dbo].[CalculateAmount](ID, PRICE) AS PRICE
along with the select statement.