I am trying to pass a variable to a function that will tell the function which select statement to perform. I've noticed that I can do this by using a table value function but I wanted to do a scaler value function.
For simplicity, I simplified my select statement.
I can't get that to work. I've tried variations, but it doesn't seem to get it through the complier such that I can even create the function.
I can do...
I suspect you can't have multiple select statements in a non table valued function.
So is it possible? Am I missing something?
For simplicity, I simplified my select statement.
Code:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION dbo.fnKeith (@CessionNumber varchar(255), @ReportMonth Int, @ReportYear Int)
RETURNS decimal(10,2)
AS
BEGIN
DECLARE @Result as Decimal(10,2)
IF @CessionNumber in (Null, '')
begin
Select @Result = ADDReinsure from
SELECT volume as ADDReinsure
from reports
where reportmonth= @ReportMonth
and reportyear= @ReportYear
END
IF @CessionNumber not in (Null, '')
begin
Select @Result = ADDReinsure from
SELECT volume as ADDReinsure
from reportPS
where reportmonth= @ReportMonth
and reportyear= @ReportYear
end
return @result
END
GO
I can't get that to work. I've tried variations, but it doesn't seem to get it through the complier such that I can even create the function.
I can do...
Code:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create FUNCTION [dbo].fnTableKeith (@CessionNumber varchar(255), @ReportMonth Int, @ReportYear Int)
RETURNS @Orders TABLE (LifeID INT, ADDReinsure decimal(10,2))
AS
begin
IF @CessionNumber in (Null, '')
begin
INSERT INTO @Orders (ADDReinsure)
Select @Result = ADDReinsure from
SELECT volume as ADDReinsure
from reports
where reportmonth= @ReportMonth
and reportyear= @ReportYear
END
IF @CessionNumber not in (Null, '')
begin
INSERT INTO @Orders (ADDReinsure)
Select @Result = ADDReinsure from
SELECT volume as ADDReinsure
from ReportPS
where reportmonth= @ReportMonth
and reportyear= @ReportYear
end
RETURN
end
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
I suspect you can't have multiple select statements in a non table valued function.
So is it possible? Am I missing something?