ALTER FUNCTION [dbo].[getCourseCost]
(
@CourseCode varchar(50),
@Year nchar(10),
@Period nchar(10)
)
RETURNS int
AS
BEGIN
DECLARE @Pnr_personal varchar(50)
DECLARE @Timlön_personal int
DECLARE @Antal_timmar_personal int
DECLARE @Kostnad_personal int
DECLARE @Kostnad_labass int
SELECT @Pnr_personal = Personnummer FROM Bemannas_Av WHERE Period = @Period AND Läsår = @Year AND Kurskod = @CourseCode
SELECT @Timlön_personal = Timlön FROM Personal WHERE Personnummer = @Pnr_personal
SELECT @Antal_timmar_personal = Antal_Timmar FROM Bemannas_Av WHERE Period = @Period AND Läsår = @Year AND Kurskod = @CourseCode
SELECT @Kostnad_labass = (Antal_timmar * Timlön) FROM Labass WHERE Period = @Period AND Läsår = @Year AND Kurser = @CourseCode
SET @Kostnad_personal = @Timlön_personal * @Antal_timmar_personal
IF @Kostnad_personal = NULL
BEGIN
SET @Kostnad_personal = 0
END
IF @Kostnad_labass = NULL
BEGIN
SET @Kostnad_labass = 0
END
RETURN @Kostnad_personal + @Kostnad_labass
END
データベースで使用されている値が NULL でない場合でも、これは NULL を返し続けます。