Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Equivalent of VFP's EMPTY() function
Message
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01143680
Message ID:
01143741
Views:
8
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--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform