USE [JCS] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER FUNCTION [dbo].[GetLaborTotal] ( -- Job Number to be passed into function @tcJobNo Char(6) ) RETURNS Numeric(12,2) AS BEGIN DECLARE @nRetVal Numeric(12,2) IF CAST(@tcJobNo AS int) = 0 SET @nRetVal = 0.00 ELSE BEGIN DECLARE @nTOTOH Numeric(12,0) -- Get sum of labor SET @nTOTOH = (SELECT sum(nHours * nRate) FROM dbo.JCProd WHERE cJobno = @tcJobNo) -- Return the total of hours multiplied by rate SET @nRetVal = ISNULL(@nTOTOH, 0) END RETURN @nRetval ENDI was then trying to test it with the following code.
SELECT JCMAST.cjobno, Dbo.GetLaborTotal(JCMAST.cjobno) AS nTOTOH FROM DBO.JCMASTThe problem is I get the following error when testing. It appears to the related to the cJobno parameter. The cJobNo field in the table is defined as char(6) and contains values such as "001056" and "main ". If I specifically pass a value such as "001056" it works.