on 03-29-2015 6:40 PM
Hi,
I have an alphanumeric UDF like this: NETT1000
I would like to get "1000" only from this field?
Hi John,
to get the numeric value from alphanumeric field first you need to create the function
use the below function code
CREATE FUNCTION Numeric_from_string
(@alphaNumeric VARCHAR(256))
RETURNS VARCHAR(256)
AS
BEGIN
DECLARE @intalpha int
SET @intalpha = PATINDEX('%[^0-9]%', @alphaNumeric)
BEGIN
WHILE @intalpha > 0
BEGIN
SET @alphaNumeric = STUFF(@alphaNumeric, @intalpha, 1, '' )
SET @intalpha = PATINDEX('%[^0-9]%', @alphaNumeric )
END
END
RETURN ISNULL(@alphaNumeric,0)
END
after creating the above function use this function in your fms
SELECT DBO.Numeric_from_string($[Table_name.udf]) as Number
i.e.
SELECT DBO.Numeric_from_string('NETT1000') as Number
this will return only 1000 .
Hope it help you.
--Manish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
a more commonly used way is to use Regular expression in SQL
So far this is the easiest way to implement Regular expression I have ever seen.
Frank
try this
SELECT DBO.Numeric_from_string(t0.U_BarPrice) as Number FROM OITM T0 WHERE T0.[ItemCode] = $[$23.1.0]
below in bold was issue alias of table
SELECT DBO.Numeric_from_string(OITM.U_BarPrice) as Number FROM OITM T0 WHERE T0.[ItemCode] = $[$23.1.0]
--Manish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.