IF LEN(@tcSaleNo) = 0 -- Only spaces ... -- If string includes numbers only IF CAST(@tcSaleNo AS int) = 0 -- Only spaces or 0's ...>I'm experimenting with creating a UDF to return a current customer balance. Here's the code I have so far...
>ALTER FUNCTION [dbo].[GetCustomerBalance] >( > -- Add the parameters for the function here > @tcSaleNo Char(6) > ) >RETURNS Money >AS >BEGIN > -- Declare the return variable here > DECLARE @yContractTotal Money > DECLARE @yPaidTotal Money > > -- Add the T-SQL statements to compute the return value here > SET @yContractTotal = (SELECT SUM(yBALANCE) > FROM dbo.TRANX > WHERE cTRANNO = @tcSaleNo > AND UPPER(cPMTMETHOD) = 'ACCOUNT') > SET @yPaidTotal = (SELECT SUM(yPAIDIN) > FROM dbo.TRANX > WHERE cCONTRACT = @tcSaleNo > AND lLATECHARGE <> 1) > > -- Return the result of the function > RETURN (ISNULL(@yContractTotal, 0) - ISNULL(@yPaidTotal, 0)) > >END >>