我是一个enzee新手,需要帮助将我们编写的MSSQL函数转换为新的Netezza设备。我不懂C ++,所以任何帮助都会受到赞赏。这是sql代码:
ALTER FUNCTION [dbo].[PMT]
(
-- Add the parameters for the function here
@Term float,
@Rate float,
@LoanSize float
)
RETURNS float
AS
BEGIN
-- Declare the return variable here
DECLARE @Result float
DECLARE @NewRate float
set @NewRate = @Rate/1200
-- Add the T-SQL statements to compute the return value here
SELECT @Result =
case when @NewRate = 0 then
@LoanSize/@Term
else
@LoanSize/((1-(1/POWER(1+@NewRate,@Term)))/(@NewRate))
end
-- Return the result of the function
RETURN @Result
END
答案 0 :(得分:0)
无法在UDF中完成查询。传递给UDF的所有内容都在每一行上执行。如果UDF是确定性的,则每行将返回一个答案。我没有看到任何需要UDF的内容
select somenum as newrate, somename as term, somenum as loansize,
case
when NewRate = 0
then LoanSize/Term
else LoanSize/((1-(1/POWER(1+NewRate,Term)))/(NewRate))
end as mynewcol