Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Equivalent of VFP's EMPTY() function
Message
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01143680
Message ID:
01143741
Vues:
6
This message has been marked as the solution to the initial question of the thread.
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
>
>
>I'm thinking I'm losing some performance and getting bad data due to the parameter being blank or zero in some cases. In VFP, I'd check for IF NOT EMPTY(tcSaleNo) and return 0. What's the best way to do the same in a SQL Server (2005) UDF?
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform