Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
UDF for determining a character in a numeric string
Message
From
16/12/2002 17:37:46
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00733424
Message ID:
00733457
Views:
44
Thank you very much. I will give it a try.

>Of the top of my head.
>IF EXISTS (SELECT *
>	   FROM   sysobjects
>	   WHERE  name = N'ufn_ValidateSSN')
>	DROP FUNCTION ufn_ValidateSSN
>GO
>
>CREATE FUNCTION ufn_ValidateSSN
>	(@SSN char(11))
>RETURNS int
>AS
>BEGIN
>	DECLARE @Ret int, @i int
>        SET @I = 1
>	WHILE @I <= LEN(@SSN)
>	BEGIN
>		IF @I IN (4, 7)
>			BEGIN IF SUBSTRING(@SSN, @I,1) <> '-' BREAK END
>		ELSE
>		IF NOT (SUBSTRING(@SSN, @I,1) BETWEEN '0' AND '9') BREAK
>		SET @I = @i + 1
>	END
>	
>	RETURN CASE WHEN @I <= LEN(@SSN) THEN 0 ELSE 1 END
>END
>
>>I need to write a UDF to validate existing SSN in our system. We have found numerous SSN's with a character in the number. The numbers were imported from another system that did not validate the information.
>>
>>I need to look at each position in the ssn and determine if it is a character or a number.
>>
>>@ivalue = ASCII(SUBSTR(@cssn, @iposition, 1)
>>
>>Then I look to see the value of @ivalue is between 48 and 57.
>>
>>Any ideas?
Fred Lauckner

You know, it works on my computer. I don't know what your problem is.

.Net aint so bad.
Previous
Reply
Map
View

Click here to load this message in the networking platform